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

Move Metadata config bag type into a stable crate #3325

Merged
merged 6 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 7 additions & 1 deletion CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@
# message = "Fix typos in module documentation for generated crates"
# references = ["smithy-rs#920"]
# meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"}
# author = "rcoh"
# author = "rcoh"

[[smithy-rs]]
message = "The `Metadata` storable was moved from aws_smithy_http into aws_smithy_runtime_api. A deprecated type alias was left in place with a note showing where the new location is."
references = ["smithy-rs#3325"]
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client" }
author = "jdisanti"
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MetadataCustomization(
private val runtimeConfig = codegenContext.runtimeConfig
private val codegenScope by lazy {
arrayOf(
"Metadata" to RuntimeType.operationModule(runtimeConfig).resolve("Metadata"),
"Metadata" to RuntimeType.smithyRuntimeApiClient(runtimeConfig).resolve("client::orchestrator::Metadata"),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class ProtocolParserGenerator(
"Headers" to RuntimeType.headers(codegenContext.runtimeConfig),
"Response" to RuntimeType.smithyRuntimeApi(codegenContext.runtimeConfig).resolve("http::Response"),
"http" to RuntimeType.Http,
"operation" to RuntimeType.operationModule(codegenContext.runtimeConfig),
"SdkBody" to RuntimeType.sdkBody(codegenContext.runtimeConfig),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class RequestSerializerGenerator(
"HttpRequest" to runtimeApi.resolve("client::orchestrator::HttpRequest"),
"HttpRequestBuilder" to RuntimeType.HttpRequestBuilder,
"Input" to interceptorContext.resolve("Input"),
"operation" to RuntimeType.operationModule(codegenContext.runtimeConfig),
"SerializeRequest" to runtimeApi.resolve("client::ser_de::SerializeRequest"),
"SdkBody" to RuntimeType.sdkBody(codegenContext.runtimeConfig),
"HeaderSerializationSettings" to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MetadataCustomizationTest {
"BoxError" to RuntimeType.boxError(runtimeConfig),
"ConfigBag" to RuntimeType.configBag(runtimeConfig),
"Intercept" to RuntimeType.intercept(runtimeConfig),
"Metadata" to RuntimeType.operationModule(runtimeConfig).resolve("Metadata"),
"Metadata" to RuntimeType.smithyRuntimeApiClient(runtimeConfig).resolve("client::orchestrator::Metadata"),
"capture_request" to RuntimeType.captureRequest(runtimeConfig),
"RuntimeComponents" to
RuntimeType.smithyRuntimeApiClient(runtimeConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,6 @@ data class RuntimeType(val path: String, val dependency: RustDependency? = null)

fun operation(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).resolve("operation::Operation")

fun operationModule(runtimeConfig: RuntimeConfig) = smithyHttp(runtimeConfig).resolve("operation")

fun protocolTest(
runtimeConfig: RuntimeConfig,
func: String,
Expand Down
1 change: 1 addition & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Without this configuration, the workspace will be read from `rust-runtime`, causing the build to fail.
[workspace]
resolver = "2"
members = [
"pokemon-service-common",
"pokemon-service",
Expand Down
2 changes: 2 additions & 0 deletions examples/pokemon-service-client-usage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ aws-smithy-types = { path = "../../rust-runtime/aws-smithy-types/" }
# Required for `HyperClientBuilder` in `client-connector` example.
aws-smithy-runtime = { path = "../../rust-runtime/aws-smithy-runtime/", features=["test-util"] }

# Required for `Metadata` in `custom-header-using-interceptor` example.
aws-smithy-runtime-api = { path = "../../rust-runtime/aws-smithy-runtime-api/", features=["client"] }


hyper = { version = "0.14.25", features = ["client", "full"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
///
use std::{collections::HashMap, time::Duration};

use aws_smithy_runtime_api::client::orchestrator::Metadata;
use pokemon_service_client::config::{ConfigBag, Intercept};
use pokemon_service_client::Client as PokemonClient;
use pokemon_service_client::{
Expand Down Expand Up @@ -77,9 +78,7 @@ impl Intercept for TtlHeaderInterceptor {
cfg: &mut ConfigBag,
) -> Result<(), BoxError> {
// Metadata in the ConfigBag has the operation name.
let metadata = cfg
.load::<aws_smithy_http::operation::Metadata>()
.expect("metadata should exist");
let metadata = cfg.load::<Metadata>().expect("metadata should exist");
let operation_name = metadata.name();

// Get operation specific or default HeaderValue to set for the header key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
use aws_smithy_runtime_api::client::orchestrator::Metadata;
/// This example demonstrates how response headers can be examined before they are deserialized
/// into the output type.
///
Expand Down Expand Up @@ -88,9 +89,7 @@ impl Intercept for ResponseHeaderLoggingInterceptor {
cfg: &mut ConfigBag,
) -> Result<(), BoxError> {
// `Metadata` in the `ConfigBag` has the operation name in it.
let metadata = cfg
.load::<aws_smithy_http::operation::Metadata>()
.expect("metadata should exist");
let metadata = cfg.load::<Metadata>().expect("metadata should exist");
let operation_name = metadata.name().to_string();

// Get the server side request ID and set it in the RequestID data type
Expand Down
43 changes: 6 additions & 37 deletions rust-runtime/aws-smithy-http/src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,11 @@
* SPDX-License-Identifier: Apache-2.0
*/

//! Types for representing the interaction between a service an a client, referred to as an "operation" in smithy.
//! Clients "send" operations to services, which are composed of 1 or more HTTP requests.

use aws_smithy_types::config_bag::{Storable, StoreReplace};
use std::borrow::Cow;
//! Deprecated metadata type.

/// Metadata added to the [`ConfigBag`](aws_smithy_types::config_bag::ConfigBag) that identifies the API being called.
#[derive(Clone, Debug)]
pub struct Metadata {
operation: Cow<'static, str>,
service: Cow<'static, str>,
}

impl Metadata {
/// Returns the operation name.
pub fn name(&self) -> &str {
&self.operation
}

/// Returns the service name.
pub fn service(&self) -> &str {
&self.service
}

/// Creates [`Metadata`].
pub fn new(
operation: impl Into<Cow<'static, str>>,
service: impl Into<Cow<'static, str>>,
) -> Self {
Metadata {
operation: operation.into(),
service: service.into(),
}
}
}

impl Storable for Metadata {
type Storer = StoreReplace<Self>;
}
#[deprecated(
since = "0.60.2",
note = "Use aws_smithy_runtime_api::client::orchestrator::Metadata instead."
)]
pub type Metadata = aws_smithy_runtime_api::client::orchestrator::Metadata;
35 changes: 35 additions & 0 deletions rust-runtime/aws-smithy-runtime-api/src/client/orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::client::interceptors::InterceptorError;
use crate::client::result::{ConnectorError, SdkError};
use aws_smithy_types::config_bag::{Storable, StoreReplace};
use bytes::Bytes;
use std::borrow::Cow;
use std::error::Error as StdError;
use std::fmt;

Expand Down Expand Up @@ -287,3 +288,37 @@ impl From<Error> for OrchestratorError<Error> {
Self::operation(err)
}
}

/// Metadata added to the [`ConfigBag`](aws_smithy_types::config_bag::ConfigBag) that identifies the API being called.
#[derive(Clone, Debug)]
pub struct Metadata {
operation: Cow<'static, str>,
service: Cow<'static, str>,
}

impl Metadata {
/// Returns the operation name.
pub fn name(&self) -> &str {
&self.operation
}

/// Returns the service name.
pub fn service(&self) -> &str {
&self.service
}

/// Creates [`Metadata`].
pub fn new(
operation: impl Into<Cow<'static, str>>,
service: impl Into<Cow<'static, str>>,
) -> Self {
Metadata {
operation: operation.into(),
service: service.into(),
}
}
}

impl Storable for Metadata {
type Storer = StoreReplace<Self>;
}
Loading