Skip to content

Commit ee5aadc

Browse files
authored
Make endpoint resolution async (#2816)
## Motivation and Context Make endpoint resolution async from the perspective of the orchestrator. - #2608 ## Description Change the endpoint trait in the orchestrator to be asynchronous ## Testing - compiled code ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
1 parent 80de569 commit ee5aadc

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

rust-runtime/aws-smithy-runtime-api/src/client/orchestrator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl Storable for EndpointResolverParams {
135135
}
136136

137137
pub trait EndpointResolver: Send + Sync + fmt::Debug {
138-
fn resolve_endpoint(&self, params: &EndpointResolverParams) -> Result<Endpoint, BoxError>;
138+
fn resolve_endpoint(&self, params: &EndpointResolverParams) -> Future<Endpoint>;
139139
}
140140

141141
#[derive(Debug)]
@@ -148,7 +148,7 @@ impl DynEndpointResolver {
148148
}
149149

150150
impl EndpointResolver for DynEndpointResolver {
151-
fn resolve_endpoint(&self, params: &EndpointResolverParams) -> Result<Endpoint, BoxError> {
151+
fn resolve_endpoint(&self, params: &EndpointResolverParams) -> Future<Endpoint> {
152152
self.0.resolve_endpoint(params)
153153
}
154154
}

rust-runtime/aws-smithy-runtime/src/client/orchestrator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ async fn try_attempt(
261261
stop_point: StopPoint,
262262
) {
263263
halt_on_err!([ctx] => interceptors.read_before_attempt(ctx, cfg));
264-
halt_on_err!([ctx] => orchestrate_endpoint(ctx, cfg).map_err(OrchestratorError::other));
264+
halt_on_err!([ctx] => orchestrate_endpoint(ctx, cfg).await.map_err(OrchestratorError::other));
265265
halt_on_err!([ctx] => interceptors.modify_before_signing(ctx, cfg));
266266
halt_on_err!([ctx] => interceptors.read_before_signing(ctx, cfg));
267267

rust-runtime/aws-smithy-runtime/src/client/orchestrator/endpoints.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use aws_smithy_runtime_api::box_error::BoxError;
1212
use aws_smithy_runtime_api::client::config_bag_accessors::ConfigBagAccessors;
1313
use aws_smithy_runtime_api::client::interceptors::context::InterceptorContext;
1414
use aws_smithy_runtime_api::client::orchestrator::{
15-
EndpointResolver, EndpointResolverParams, HttpRequest,
15+
EndpointResolver, EndpointResolverParams, Future, HttpRequest,
1616
};
1717
use aws_smithy_types::config_bag::{ConfigBag, Storable, StoreReplace};
1818
use aws_smithy_types::endpoint::Endpoint;
@@ -40,8 +40,10 @@ impl StaticUriEndpointResolver {
4040
}
4141

4242
impl EndpointResolver for StaticUriEndpointResolver {
43-
fn resolve_endpoint(&self, _params: &EndpointResolverParams) -> Result<Endpoint, BoxError> {
44-
Ok(Endpoint::builder().url(self.endpoint.to_string()).build())
43+
fn resolve_endpoint(&self, _params: &EndpointResolverParams) -> Future<Endpoint> {
44+
Future::ready(Ok(Endpoint::builder()
45+
.url(self.endpoint.to_string())
46+
.build()))
4547
}
4648
}
4749

@@ -86,17 +88,19 @@ impl<Params> EndpointResolver for DefaultEndpointResolver<Params>
8688
where
8789
Params: Debug + Send + Sync + 'static,
8890
{
89-
fn resolve_endpoint(&self, params: &EndpointResolverParams) -> Result<Endpoint, BoxError> {
90-
match params.get::<Params>() {
91-
Some(params) => Ok(self.inner.resolve_endpoint(params)?),
91+
fn resolve_endpoint(&self, params: &EndpointResolverParams) -> Future<Endpoint> {
92+
let ep = match params.get::<Params>() {
93+
Some(params) => self.inner.resolve_endpoint(params).map_err(Box::new),
9294
None => Err(Box::new(ResolveEndpointError::message(
9395
"params of expected type was not present",
9496
))),
9597
}
98+
.map_err(|e| e as _);
99+
Future::ready(ep)
96100
}
97101
}
98102

99-
pub(super) fn orchestrate_endpoint(
103+
pub(super) async fn orchestrate_endpoint(
100104
ctx: &mut InterceptorContext,
101105
cfg: &mut ConfigBag,
102106
) -> Result<(), BoxError> {
@@ -105,7 +109,7 @@ pub(super) fn orchestrate_endpoint(
105109
let request = ctx.request_mut().expect("set during serialization");
106110

107111
let endpoint_resolver = cfg.endpoint_resolver();
108-
let endpoint = endpoint_resolver.resolve_endpoint(params)?;
112+
let endpoint = endpoint_resolver.resolve_endpoint(params).await?;
109113
apply_endpoint(request, &endpoint, endpoint_prefix)?;
110114

111115
// Make the endpoint config available to interceptors

0 commit comments

Comments
 (0)