Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix subtle break of endpoint prefixes due to semver #3318

Merged
merged 13 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-config/src/ecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
use crate::http_credential_provider::HttpCredentialProvider;
use crate::provider_config::ProviderConfig;
use aws_credential_types::provider::{self, error::CredentialsError, future, ProvideCredentials};
use aws_smithy_http::endpoint::apply_endpoint;
use aws_smithy_runtime::client::endpoint::apply_endpoint;
use aws_smithy_runtime_api::client::dns::{ResolveDns, ResolveDnsError, SharedDnsResolver};
use aws_smithy_runtime_api::client::http::HttpConnectorSettings;
use aws_smithy_runtime_api::shared::IntoShared;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ internal class EndpointTraitBindingsTest {
)
implBlock(symbolProvider.toSymbol(model.lookup("test#GetStatusInput"))) {
rustBlockTemplate(
"fn endpoint_prefix(&self) -> std::result::Result<#{endpoint}::EndpointPrefix, #{endpoint}::error::InvalidEndpointError>",
"endpoint" to RuntimeType.smithyHttp(TestRuntimeConfig).resolve("endpoint"),
"fn endpoint_prefix(&self) -> std::result::Result<#{EndpointPrefix}, #{InvalidEndpointError}>",
"EndpointPrefix" to RuntimeType.smithyRuntimeApiClient(TestRuntimeConfig).resolve("client::endpoint::EndpointPrefix"),
"InvalidEndpointError" to RuntimeType.smithyRuntimeApiClient(TestRuntimeConfig).resolve("client::endpoint::error::InvalidEndpointError"),
) {
endpointBindingGenerator.render(this, "self")
}
Expand Down Expand Up @@ -159,8 +160,8 @@ internal class EndpointTraitBindingsTest {
"""
async fn test_endpoint_prefix() {
use #{capture_request};
use aws_smithy_http::endpoint::EndpointPrefix;
use aws_smithy_runtime_api::box_error::BoxError;
use aws_smithy_runtime_api::client::endpoint::EndpointPrefix;
use aws_smithy_runtime_api::client::runtime_components::RuntimeComponents;
use aws_smithy_types::body::SdkBody;
use aws_smithy_types::config_bag::ConfigBag;
Expand Down
68 changes: 35 additions & 33 deletions rust-runtime/aws-smithy-http/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,40 @@

//! Code for resolving an endpoint (URI) that a request should be sent to

#![allow(deprecated)]

use crate::endpoint::error::InvalidEndpointError;
use http::uri::{Authority, Uri};
use std::borrow::Cow;
use std::fmt::Debug;
use std::result::Result as StdResult;
use std::str::FromStr;

use http::uri::{Authority, Uri};

use aws_smithy_types::config_bag::{Storable, StoreReplace};
pub use error::ResolveEndpointError;

use crate::endpoint::error::InvalidEndpointError;

pub mod error;

/// An endpoint-resolution-specific Result. Contains either an [`Endpoint`](aws_smithy_types::endpoint::Endpoint) or a [`ResolveEndpointError`].
#[deprecated(since = "0.60.1", note = "Was never used.")]
pub type Result = std::result::Result<aws_smithy_types::endpoint::Endpoint, ResolveEndpointError>;

/// A special type that adds support for services that have special URL-prefixing rules.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct EndpointPrefix(String);
impl EndpointPrefix {
/// Create a new endpoint prefix from an `impl Into<String>`. If the prefix argument is invalid,
/// a [`InvalidEndpointError`] will be returned.
pub fn new(prefix: impl Into<String>) -> StdResult<Self, InvalidEndpointError> {
let prefix = prefix.into();
match Authority::from_str(&prefix) {
Ok(_) => Ok(EndpointPrefix(prefix)),
Err(err) => Err(InvalidEndpointError::failed_to_construct_authority(
prefix, err,
)),
}
}

/// Get the `str` representation of this `EndpointPrefix`.
pub fn as_str(&self) -> &str {
&self.0
}
}

impl Storable for EndpointPrefix {
type Storer = StoreReplace<Self>;
}
#[deprecated(
since = "0.60.1",
note = "Use aws_smithy_runtime_api::client::endpoint::EndpointPrefix instead."
)]
pub type EndpointPrefix = aws_smithy_runtime_api::client::endpoint::EndpointPrefix;

/// Apply `endpoint` to `uri`
///
/// This method mutates `uri` by setting the `endpoint` on it
#[deprecated(
since = "0.60.1",
note = "Use aws_smithy_runtime::client::endpoint::apply_endpoint instead."
)]
pub fn apply_endpoint(
uri: &mut Uri,
endpoint: &Uri,
prefix: Option<&EndpointPrefix>,
) -> StdResult<(), InvalidEndpointError> {
jdisanti marked this conversation as resolved.
Show resolved Hide resolved
let prefix = prefix.map(|p| p.0.as_str()).unwrap_or("");
let prefix = prefix.map(EndpointPrefix::as_str).unwrap_or("");
let authority = endpoint
.authority()
.as_ref()
Expand Down Expand Up @@ -100,3 +82,23 @@ fn merge_paths<'a>(endpoint: &'a Uri, uri: &'a Uri) -> Cow<'a, str> {
Cow::Owned(format!("{}/{}", ep_no_slash, uri_path_no_slash))
}
}

/// Errors related to endpoint resolution and validation
pub mod error {
/// Endpoint resolution failed
#[deprecated(
since = "0.60.1",
note = "Use aws_smithy_runtime_api::client::endpoint::error::ResolveEndpointError instead."
)]
pub type ResolveEndpointError =
aws_smithy_runtime_api::client::endpoint::error::ResolveEndpointError;

/// An error that occurs when an endpoint is found to be invalid. This usually occurs due to an
/// incomplete URI.
#[deprecated(
since = "0.60.1",
note = "Use aws_smithy_runtime_api::client::endpoint::error::InvalidEndpointError instead."
)]
pub type InvalidEndpointError =
aws_smithy_runtime_api::client::endpoint::error::InvalidEndpointError;
}
jdisanti marked this conversation as resolved.
Show resolved Hide resolved
137 changes: 0 additions & 137 deletions rust-runtime/aws-smithy-http/src/endpoint/error.rs

This file was deleted.

Loading
Loading