Skip to content

Commit

Permalink
Merge branch 'main' into harryb/remove-error-kind
Browse files Browse the repository at this point in the history
  • Loading branch information
hlbarber authored Oct 7, 2022
2 parents 236d6ea + 238cf8b commit 3cfdaf5
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 18 deletions.
30 changes: 29 additions & 1 deletion CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@
# meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"}
# author = "rcoh"

[[smithy-rs]]
message = """
Replace all usages of `AtomicU64` with `AtomicUsize` to support 32bit targets.
"""
references = ["smithy-rs#1811"]
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "server"}
author = "LukeMathWalker"

[[smithy-rs]]
message = """
Replace all usages of `AtomicU64` with `AtomicUsize` to support 32bit targets.
"""
references = ["smithy-rs#1811"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client"}
author = "LukeMathWalker"

[[smithy-rs]]
message = """
Mark `operation` and `operation_handler` modules as private in the generated server crate.
Expand All @@ -20,6 +36,12 @@ references = ["smithy-rs#1803"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server"}
author = "LukeMathWalker"

[[smithy-rs]]
message = "Sensitive fields in errors now respect @sensitive trait and are properly redacted."
references = ["smithy-rs#1802"]
meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "all" }
author = "jjant"

[[smithy-rs]]
message = "Pokémon Service example code now runs clippy during build."
references = ["smithy-rs#1727"]
Expand Down Expand Up @@ -101,11 +123,17 @@ author = "jdisanti"
[[smithy-rs]]
message = "Paginators now stop on encountering a duplicate token by default rather than panic. This behavior can be customized by toggling the `stop_on_duplicate_token` property on the paginator before calling `send`."
references = ["aws-sdk-rust#620", "smithy-rs#1748"]
meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "client"}
meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "client" }
author = "jdisanti"

[[aws-sdk-rust]]
message = "The client Config now has getters for every value that it holds."
references = ["smithy-rs#1747"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "kastolars"

[[aws-sdk-rust]]
message = "Fix regression where `connect_timeout` and `read_timeout` fields are unused in the IMDS client"
references = ["smithy-rs#1822"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "kevinpark1217"
4 changes: 2 additions & 2 deletions aws/rust-runtime/aws-config/src/imds/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,8 @@ impl Builder {
pub async fn build(self) -> Result<Client, BuildError> {
let config = self.config.unwrap_or_default();
let timeout_config = TimeoutConfig::builder()
.connect_timeout(DEFAULT_CONNECT_TIMEOUT)
.read_timeout(DEFAULT_READ_TIMEOUT)
.connect_timeout(self.connect_timeout.unwrap_or(DEFAULT_CONNECT_TIMEOUT))
.read_timeout(self.read_timeout.unwrap_or(DEFAULT_READ_TIMEOUT))
.build();
let connector_settings = ConnectorSettings::from_timeout_config(&timeout_config);
let connector = expect_connector(config.connector(&connector_settings));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ open class StructureGenerator(
fun render(forWhom: CodegenTarget = CodegenTarget.CLIENT) {
renderStructure()
errorTrait?.also { errorTrait ->
ErrorGenerator(symbolProvider, writer, shape, errorTrait).render(forWhom)
ErrorGenerator(model, symbolProvider, writer, shape, errorTrait).render(forWhom)
}
}

Expand Down Expand Up @@ -109,6 +109,7 @@ open class StructureGenerator(
members.forEach { member ->
val memberName = symbolProvider.toMemberName(member)
val fieldValue = member.redactIfNecessary(model, "self.$memberName")

rust(
"formatter.field(${memberName.dq()}, &$fieldValue);",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package software.amazon.smithy.rust.codegen.core.smithy.generators.error

import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.model.traits.ErrorTrait
import software.amazon.smithy.model.traits.RetryableTrait
Expand All @@ -19,10 +20,12 @@ import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.StdError
import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider
import software.amazon.smithy.rust.codegen.core.smithy.isOptional
import software.amazon.smithy.rust.codegen.core.util.REDACTION
import software.amazon.smithy.rust.codegen.core.util.dq
import software.amazon.smithy.rust.codegen.core.util.errorMessageMember
import software.amazon.smithy.rust.codegen.core.util.getTrait
import software.amazon.smithy.rust.codegen.core.util.letIf
import software.amazon.smithy.rust.codegen.core.util.shouldRedact

sealed class ErrorKind {
abstract fun writable(runtimeConfig: RuntimeConfig): Writable
Expand Down Expand Up @@ -60,6 +63,7 @@ fun StructureShape.modeledRetryKind(errorTrait: ErrorTrait): ErrorKind? {
}

class ErrorGenerator(
private val model: Model,
private val symbolProvider: RustSymbolProvider,
private val writer: RustWriter,
private val shape: StructureShape,
Expand Down Expand Up @@ -118,8 +122,12 @@ class ErrorGenerator(
}
write("write!(f, ${errorDesc.dq()})?;")
messageShape?.let {
ifSet(it, symbolProvider.toSymbol(it), "&self.message") { field ->
write("""write!(f, ": {}", $field)?;""")
if (it.shouldRedact(model)) {
write("""write!(f, ": {}", $REDACTION)?;""")
} else {
ifSet(it, symbolProvider.toSymbol(it), "&self.message") { field ->
write("""write!(f, ": {}", $field)?;""")
}
}
}
write("Ok(())")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,19 @@ fun ServiceShape.hasEventStreamOperations(model: Model): Boolean = operations.an
model.expectShape(id, OperationShape::class.java).isEventStream(model)
}

fun Shape.redactIfNecessary(model: Model, safeToPrint: String): String =
fun Shape.shouldRedact(model: Model): Boolean =
when (this) {
is MemberShape -> model.expectShape(this.target).redactIfNecessary(model, safeToPrint)
else -> if (this.hasTrait<SensitiveTrait>()) {
"*** Sensitive Data Redacted ***".dq()
} else {
safeToPrint
}
is MemberShape -> model.expectShape(this.target).shouldRedact(model)
else -> this.hasTrait<SensitiveTrait>()
}

const val REDACTION = "\"*** Sensitive Data Redacted ***\""

fun Shape.redactIfNecessary(model: Model, safeToPrint: String): String =
if (this.shouldRedact(model)) {
REDACTION
} else {
safeToPrint
}

/*
Expand Down
6 changes: 3 additions & 3 deletions rust-runtime/aws-smithy-client/src/never.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use http::Uri;
use aws_smithy_async::future::never::Never;

use std::marker::PhantomData;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;

use std::task::{Context, Poll};
Expand All @@ -27,7 +27,7 @@ use tower::BoxError;
#[derive(Debug)]
pub struct NeverService<Req, Resp, Err> {
_resp: PhantomData<(Req, Resp, Err)>,
invocations: Arc<AtomicU64>,
invocations: Arc<AtomicUsize>,
}

impl<Req, Resp, Err> Clone for NeverService<Req, Resp, Err> {
Expand Down Expand Up @@ -55,7 +55,7 @@ impl<Req, Resp, Err> NeverService<Req, Resp, Err> {
}

/// Returns the number of invocations made to this service
pub fn num_calls(&self) -> u64 {
pub fn num_calls(&self) -> usize {
self.invocations.load(Ordering::SeqCst)
}
}
Expand Down
8 changes: 8 additions & 0 deletions rust-runtime/aws-smithy-http-server-python/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ impl PySocket {
}

#[cfg(test)]
// `is_listener` on `Socket` is only available on certain platforms.
// In particular, this fails to compile on MacOS.
#[cfg(any(
target_os = "android",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "linux",
))]
mod tests {
use super::*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use std::{
collections::HashMap,
convert::TryInto,
sync::{atomic::AtomicU64, Arc},
sync::{atomic::AtomicUsize, Arc},
};

use async_stream::stream;
Expand Down Expand Up @@ -108,7 +108,7 @@ struct PokemonTranslations {
#[derive(Debug)]
pub struct State {
pokemons_translations: HashMap<String, PokemonTranslations>,
call_count: AtomicU64,
call_count: AtomicUsize,
}

impl Default for State {
Expand Down

0 comments on commit 3cfdaf5

Please sign in to comment.