* Use `Sensitive` wrapper in Debug impl for structures
* Fix using the wrong import path for `Sensitive`
* Use redactMemberIfNecessary
* Fix display implementation on errors to respect @sensitive trait
* Don't use Sensitive type just yet
* Add entry in changelog
* Improve redaction of sensitive error message
* Use correct flags in changelog
* Run ktlint
* Replace AtomicU64 with AtomicUsize to prevent compilation issues on 32 bits platforms.
* Make sure that Rust tests compile on MacOS.
* Add CHANGELOG next entry.
* Mark `operation_handler` module as private in the generated server code since it does not contain any public type.
Tune the visibility of the 'operation' module based on the rendering context
* Add changelog.next entry.
* Rename `operationModule` to `operation`.
* Ensure that `operation` is added to the list of public modules for the generated client.
* Remove DefaultModules from codegen-core
* Fix Python server.
* Expose TestDefaultPublicModules.
* Simplify Python Pokemon service
* Use `threading.Lock` instead of `multiprocessing.Lock`
Co-authored-by: Matteo Bigoi <1781140+crisidev@users.noreply.github.com>
* Explain why we need to pass `force=True`
* Add comment about synchronization of `Context` class
Co-authored-by: Matteo Bigoi <1781140+crisidev@users.noreply.github.com>
* Fix backtick fences to render code block
* Render list as a list instead of a code block.
* Indent further to get nested code block.
* Remove `ignore` descriptors.
* Move `testutil` into `core` where possible
* Move `rustlang` tests into `core`
* Move remaining `util` tests to `core`
* Move and refactor `TopLevelErrorGeneratorTest` to not require `RustCodegenPlugin`
* Move protocols into `core`
* Move `generator` tests into `core`
* Move protocol ser/de tests into `core`
* Suppress deprecation warning in `TopLevelErrorGeneratorTest`
* Move `InlineFunctionNamerTest` into `core`
* Move model transform tests into `core`
* Rename `SymbolBuilderTest` to `SymbolVisitorTest` to match class under test
* Move server classes out of client
* Move core codegen tests into their own CI step
* Add documentation covering instrumentation approaches for Smithy Rust.
* Tweak the logging in the Pokemon service to better exemplify instrumentation.
* Remove `TraceLayer` which violates sensitivity contract.
* Switch to [Pretty](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/format/struct.Pretty.html) logs to better showcase the outputs.
* Update [Logging in the Presence of Sensitive Data](https://github.com/awslabs/smithy-rs/pull/1536) checklist.
* Rename `logging` module to `instrumentation` to improve coherence across struct names and documentation.
This moves most things from `codegen-client` that should be in
`codegen-core` into `codegen-core`.
This is a continuation of the efforts started in #1697, #1730.
* Docs: generation of Pokemon service
This is an overview of the Pokémon service. It describes:
* How a smithy-rs customer uses the vanilla SDK and writes their business logic
* What the runtime is and how code is generated
* The folder structure of the project
Signed-off-by: Daniele Ahmed <ahmeddan@amazon.de>
* Simplify sensitivity detection logic by assuming bindings only exist at top level input/output.
* Fix greedy label logic - they can now exist alongside of normal labels.
* Fix `httpPrefixHeader` false positive.
* Export `RequestFmt` and `ResponseFmt` types alongside the closures.
* More extensive use of `Writable` to improve readability.
## Motivation and Context
* Customers want to be able to implement simple middleware directly in Python. This PR aims to add the initial support for it.
* Improve the idiomatic experience of logging by exposing a handler compatible with Python's standard library `logging` module.
## Description
### Middleware
A middleware is defined as a sync or async Python function that can return multiple values, following these rules:
* Middleware not returning will let the execution continue without changing the original request.
* Middleware returning a modified Request will update the original request before continuing the execution.
* Middleware returning a Response will immediately terminate the request handling and return the response constructed from Python.
* Middleware raising MiddlewareException will immediately terminate the request handling and return a protocol specific error, with the option of setting the HTTP return code.
* Middleware raising any other exception will immediately terminate the request handling and return a protocol specific error, with HTTP status code 500.
Middlewares are registered into the Python application and executed in order of registration.
Example:
from sdk import App
from sdk.middleware import Request, MiddlewareException
app = App()
@app.request_middleware
def inject_header(request: Request):
request.set_header("x-amzn-answer", "42")
return request
@app.request_middleare
def check_header(request: Request):
if request.get_header("x-amzn-answer") != "42":
raise MiddlewareException("Wrong answer", 404)
@app.request_middleware
def dump_headers(request: Request):
logging.debug(f"Request headers after middlewares: {request.headers()}")
**NOTE: this PR only adds support for request middlewares, which are executed before the operation handler. Response middlewares, executed after the operation are tracked here: https://github.com/awslabs/smithy-rs/issues/1754.**
### Logging
To improve the idiomatic experience, now logging need to be configured from the Python side by using the standard `logging` module. This allows customers to opt-out of our `tracing` based logging implementation and use their own and logging level is now driven by Python.
import logging
from sdk.logging import TracingHandler
logging.basicConfig(level=logging.INFO, handlers=[TracingHandler.handle()])
Signed-off-by: Bigo <1781140+crisidev@users.noreply.github.com>
Co-authored-by: Burak <burakvar@amazon.co.uk>
* Allow custom layers to every operation
Third-party developers can add custom functions to a service builder,
through a `BuilderModifier`.
These functionalities are applied to every operation of that service.
An example of a builder modifier can be found in
rust-runtime/aws-smithy-http-server/examples/pokemon-service/lib.rs
Signed-off-by: Harry Barber <hlbarber@amazon.co.uk>
Signed-off-by: Daniele Ahmed <ahmeddan@amazon.de>
Co-authored-by: Harry Barber <hlbarber@amazon.co.uk>
- Moves most of the `util` package from `codegen-client` into `codegen-core`
- Moves the synthetic traits into `codegen-core`
- Consolidates duplicated `RustTypesTest` files
- Corrects `lang` -> `rustlang` package name in `codegen-client` tests
- Moves `letIf` from `SymbolVisitor` into its own file in `codegen-core`
* Fix retry for native Smithy clients
* Treat `SdkError::ResponseError` as a retryable transient failure
* Rename `ClassifyResponse` to `ClassifyRetry`
* Rename 'policy' to 'classifier' in AWS SDK public API
* Rename `AwsResponseClassifier` to `AwsResponseRetryClassifier`
Co-authored-by: Zelda Hessler <zhessler@amazon.com>
Add validation for the Content-Type header and pass (remove from the failing
list) the relevant protocol tests
Signed-off-by: Daniele Ahmed <ahmeddan@amazon.de>
* Add `ServerProtocol` interface to allow for server side protocol specific methods.
* Make public the structs merged in https://github.com/awslabs/smithy-rs/pull/1679.
* Add `ServerOperationGenerator`, which generates a ZST and implements `OperationShape` on it.
* Add `ServerServiceGeneratorV2`, which generates the service newtype around a router and a service builder.
* Add `hidden` argument to `RustModule` which allows modules to be marked with `#[doc(hidden)]`.
* Add `BuildModifier` trait to provide a common interface for extending service builders.
* Add `Upgradable` trait to simplifying bounds when upgrading from an `Operation` to a HTTP service.
* Add `FromRequest`, `FromParts`, and `IntoResponse` implementations.
* Make `RoutingService` accept general body types `B` for the inner services `http::Response<B>`.
* Use new service builder in protocol tests.
* Make Instantiator generate default values for required field on demand
* Move looping over operations into ServerProtocolTestGenerator
Signed-off-by: Weihang Lo <weihanglo@users.noreply.github.com>
* Add protocol test helper functions
Signed-off-by: Weihang Lo <weihanglo@users.noreply.github.com>
* Add method param to construct http request
* Put request validation logic inside closure
Signed-off-by: Weihang Lo <weihanglo@users.noreply.github.com>
* Make protocol test response instantiate with default values
* Add module meta for helper module
Signed-off-by: Weihang Lo <weihanglo@users.noreply.github.com>
* Apply suggestions from code review
Co-authored-by: david-perez <d@vidp.dev>
* Address most style suggestions
* add companion object for attribute #[allow(dead_code)]
Signed-off-by: Weihang Lo <weihanglo@users.noreply.github.com>
* Use writable to make code readable
* recursively call `filldefaultValue`
Signed-off-by: Weihang Lo <weihanglo@users.noreply.github.com>
* Exercise with `OperationExtension`
* Temporary protocol tests fix for awslabs/smithy#1391
Missing `X-Amz-Target` in response header
* Add `X-Amz-Target` for common models
Signed-off-by: Weihang Lo <weihanglo@users.noreply.github.com>
Co-authored-by: david-perez <d@vidp.dev>
Co-authored-by: Harry Barber <hlbarber@amazon.co.uk>