-
Notifications
You must be signed in to change notification settings - Fork 30
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
feat!: add interceptor client config #704
Conversation
f269732
to
0bbf847
Compare
Codegen for smithy-lang/smithy-swift#704. Also fixes a codegen test case.
fbcac8e
to
8e4ec7c
Compare
Codegen for smithy-lang/smithy-swift#704. Also fixes a codegen test case.
8e4ec7c
to
3448636
Compare
Codegen for smithy-lang/smithy-swift#704. Also fixes a codegen test case.
@@ -13,6 +13,10 @@ public protocol RequestMessageBuilder<RequestType>: AnyObject { | |||
|
|||
init() | |||
|
|||
func withHost(_ host: String) -> Self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Host
should be provided from URI
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yea, this is just here so I could use it in a test. I think this can changed to something like withURI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one nit + please address Andrew's comment before merging
writer.write("let builder = OrchestratorBuilder<$inputSymbol, $outputSymbol, SdkHttpRequest, HttpResponse, HttpContext>()") | ||
writer.write("config.interceptorProviders.forEach { builder.interceptors.add($$0.create()) }") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: more readable if you did
config.interceptorProviders.forEach { provider in
builder.interceptors.add(provider.create())
}
config.httpInterceptorProviders.forEach { | ||
let i: any HttpInterceptor<${'$'}N, ${'$'}N> = $$0.create() | ||
builder.interceptors.add(i) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same nit here might be better to use a name instead of $0.create
for readability
3448636
to
0831020
Compare
Codegen for smithy-lang/smithy-swift#704. Also fixes a codegen test case, and updates the types of some interceptor implementations to remove AttributesType.
0831020
to
1db4723
Compare
Codegen for smithy-lang/smithy-swift#704. Also fixes a codegen test case, and updates the types of some interceptor implementations to remove AttributesType.
Codegen for smithy-lang/smithy-swift#704. Also fixes a codegen test case, and updates the types of some interceptor implementations to remove AttributesType.
350997f
to
bdbfa0b
Compare
Codegen for smithy-lang/smithy-swift#704. Also fixes a codegen test case, and updates the types of some interceptor implementations to remove AttributesType.
bdbfa0b
to
263ef6e
Compare
263ef6e
to
a0d018f
Compare
Codegen for smithy-lang/smithy-swift#704. Also updates the types of some interceptor implementations to remove AttributesType.
Codegen for smithy-lang/smithy-swift#704. Also updates the types of some interceptor implementations to remove AttributesType.
a0d018f
to
1c9d7ba
Compare
Codegen for smithy-lang/smithy-swift#704. Also updates the types of some interceptor implementations to remove AttributesType, and fixes a test case.
Codegen for smithy-lang/smithy-swift#704. Also updates the types of some interceptor implementations to remove AttributesType, and fixes a test case.
1c9d7ba
to
cb09e6f
Compare
Codegen for smithy-lang/smithy-swift#704. Also updates the types of some interceptor implementations to remove AttributesType, and fixes a test case.
cb09e6f
to
157b12f
Compare
Codegen for smithy-lang/smithy-swift#704. Also updates the types of some interceptor implementations to remove AttributesType, and fixes a test case.
@@ -31,5 +31,10 @@ public protocol DefaultClientConfiguration: ClientConfiguration { | |||
/// If none is provided, only a default logger provider will be used. | |||
var telemetryProvider: TelemetryProvider { get set } | |||
|
|||
/// Add an `InterceptorProvider` that will be used to provide interceptors for all operations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: Interceptor providers apply to Http operations + all other operations vs Http Interceptor providers apply to only http operations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct
public func updateResult(updated: Result<OutputType, Error>) { | ||
self.result = updated | ||
public func updateOutput(updated: OutputType) { | ||
self.result = .success(updated) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before updated could be an Error
, will this always be a success?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return self.attributes | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please take care of the lint issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should make these lint issues errors instead of warnings so they fail local swiftlint
runs and CI
157b12f
to
84261fe
Compare
84261fe
to
a0efc36
Compare
Codegen for smithy-lang/smithy-swift#704. Also updates the types of some interceptor implementations to remove AttributesType, and fixes a test case.
Allows configuration of interceptors on a client level by adding interceptor providers to client config, allowing Plugins to add interceptors. The primary addition is `InterceptorProvider`, an interface that creates generic interceptors which can operate on any transport - http or otherwise. When an operation is executed, interceptor providers are called to create new instances of service-level interceptors. Creating new instances also means we don't need to synchronize on the shared interceptors. Transport specific config, have their own methods for adding interceptor providers, so you can add `HttpInterceptorProvider`s to http config. Operations know which transport they operate on, and can choose which transport-specific interceptor providers to use. If/when we have operation-level configuration, it might make more sense to allow plugins to configure more generic 'operation customizations' or something, rather than just the interceptors. Operations would then call the customizations before executing. A few other minor changes were made to the client libraries: - Removed HasAttributes protocol and corresponding AttributesType from interceptor interfaces, as we now just use `Context`. - Changed InterceptorContext `getResult` to `getOutput`. We still store a `Result<OutputType, Error>` in DefaultInterceptorContext, but `getOutput` now throws that error if it is present, otherwise just returns `OutputType` - Added actual builder methods to RequestMessageBuilder, which we would need eventually, so I could use them in testing - Made SdkHttpRequestBuilder final Codegen was also updated to generate the new config methods, and to call interceptor providers in operations to add configured interceptors.
a0efc36
to
4645747
Compare
Codegen for smithy-lang/smithy-swift#704. Also updates the types of some interceptor implementations to remove AttributesType, and fixes a test case.
Codegen for smithy-lang/smithy-swift#704. Also updates the types of some interceptor implementations to remove AttributesType, and fixes a test case.
Issue #
Description of changes
Allows configuration of interceptors on a client level by adding interceptor
providers to client config, allowing Plugins to add interceptors.
The primary addition is
InterceptorProvider
, an interface that createsgeneric interceptors which can operate on any transport - http or otherwise.
When an operation is executed, interceptor providers are called to create
new instances of service-level interceptors. Creating new instances also
means we don't need to synchronize on the shared interceptors. Transport
specific config, have their own methods for adding interceptor providers, so
you can add
HttpInterceptorProvider
s to http config. Operations know whichtransport they operate on, and can choose which transport-specific interceptor
providers to use.
If/when we have operation-level configuration, it might make more sense to
allow plugins to configure more generic 'operation customizations' or
something, rather than just the interceptors. Operations would then call
the customizations before executing.
A few other minor changes were made to the client libraries:
eventually, so I could use them in testing
Codegen was also updated to generate the new config methods, and to call
interceptor providers in operations to add configured interceptors.
Scope
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.