Skip to content

Commit ce0dcde

Browse files
authored
refactor(rt): remove client options (#932)
1 parent bd016eb commit ce0dcde

File tree

16 files changed

+132
-343
lines changed

16 files changed

+132
-343
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"id": "248dac80-b9e6-49f8-ae6e-0fbdafa06a2d",
3+
"type": "misc",
4+
"description": "Remove ClientOption and associated Builder"
5+
}

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/protocol/HttpProtocolClientGenerator.kt

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -209,27 +209,23 @@ abstract class HttpProtocolClientGenerator(
209209
writer.write("deserializer = UnitDeserializer")
210210
}
211211

212-
// execution context
213-
writer.openBlock("context {", "}") {
214-
// property from implementing SdkClient
215-
writer.write("operationName = #S", op.id.name)
216-
writer.write("serviceName = #L", "ServiceId")
217-
218-
// optional endpoint trait
219-
op.getTrait<EndpointTrait>()?.let { endpointTrait ->
220-
val hostPrefix = endpointTrait.hostPrefix.segments.joinToString(separator = "") { segment ->
221-
if (segment.isLabel) {
222-
// hostLabel can only target string shapes
223-
// see: https://awslabs.github.io/smithy/1.0/spec/core/endpoint-traits.html#hostlabel-trait
224-
val member =
225-
inputShape.get().members().first { member -> member.memberName == segment.content }
226-
"\${input.${member.defaultName()}}"
227-
} else {
228-
segment.content
229-
}
212+
writer.write("operationName = #S", op.id.name)
213+
writer.write("serviceName = #L", "ServiceId")
214+
215+
// optional endpoint trait
216+
op.getTrait<EndpointTrait>()?.let { endpointTrait ->
217+
val hostPrefix = endpointTrait.hostPrefix.segments.joinToString(separator = "") { segment ->
218+
if (segment.isLabel) {
219+
// hostLabel can only target string shapes
220+
// see: https://awslabs.github.io/smithy/1.0/spec/core/endpoint-traits.html#hostlabel-trait
221+
val member =
222+
inputShape.get().members().first { member -> member.memberName == segment.content }
223+
"\${input.${member.defaultName()}}"
224+
} else {
225+
segment.content
230226
}
231-
writer.write("hostPrefix = #S", hostPrefix)
232227
}
228+
writer.write("hostPrefix = #S", hostPrefix)
233229
}
234230

235231
// telemetry

codegen/smithy-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/rendering/protocol/HttpProtocolClientGeneratorTest.kt

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,8 @@ class HttpProtocolClientGeneratorTest {
8080
val op = SdkHttpOperation.build<GetFooRequest, GetFooResponse> {
8181
serializer = GetFooOperationSerializer()
8282
deserializer = GetFooOperationDeserializer()
83-
context {
84-
operationName = "GetFoo"
85-
serviceName = ServiceId
86-
}
83+
operationName = "GetFoo"
84+
serviceName = ServiceId
8785
telemetry {
8886
provider = config.telemetryProvider
8987
scope = telemetryScope
@@ -103,10 +101,8 @@ class HttpProtocolClientGeneratorTest {
103101
val op = SdkHttpOperation.build<GetFooNoInputRequest, GetFooNoInputResponse> {
104102
serializer = GetFooNoInputOperationSerializer()
105103
deserializer = GetFooNoInputOperationDeserializer()
106-
context {
107-
operationName = "GetFooNoInput"
108-
serviceName = ServiceId
109-
}
104+
operationName = "GetFooNoInput"
105+
serviceName = ServiceId
110106
telemetry {
111107
provider = config.telemetryProvider
112108
scope = telemetryScope
@@ -126,10 +122,8 @@ class HttpProtocolClientGeneratorTest {
126122
val op = SdkHttpOperation.build<GetFooNoOutputRequest, GetFooNoOutputResponse> {
127123
serializer = GetFooNoOutputOperationSerializer()
128124
deserializer = GetFooNoOutputOperationDeserializer()
129-
context {
130-
operationName = "GetFooNoOutput"
131-
serviceName = ServiceId
132-
}
125+
operationName = "GetFooNoOutput"
126+
serviceName = ServiceId
133127
telemetry {
134128
provider = config.telemetryProvider
135129
scope = telemetryScope
@@ -149,10 +143,8 @@ class HttpProtocolClientGeneratorTest {
149143
val op = SdkHttpOperation.build<GetFooStreamingInputRequest, GetFooStreamingInputResponse> {
150144
serializer = GetFooStreamingInputOperationSerializer()
151145
deserializer = GetFooStreamingInputOperationDeserializer()
152-
context {
153-
operationName = "GetFooStreamingInput"
154-
serviceName = ServiceId
155-
}
146+
operationName = "GetFooStreamingInput"
147+
serviceName = ServiceId
156148
telemetry {
157149
provider = config.telemetryProvider
158150
scope = telemetryScope
@@ -172,10 +164,8 @@ class HttpProtocolClientGeneratorTest {
172164
val op = SdkHttpOperation.build<GetFooStreamingOutputRequest, GetFooStreamingOutputResponse> {
173165
serializer = GetFooStreamingOutputOperationSerializer()
174166
deserializer = GetFooStreamingOutputOperationDeserializer()
175-
context {
176-
operationName = "GetFooStreamingOutput"
177-
serviceName = ServiceId
178-
}
167+
operationName = "GetFooStreamingOutput"
168+
serviceName = ServiceId
179169
telemetry {
180170
provider = config.telemetryProvider
181171
scope = telemetryScope
@@ -195,10 +185,8 @@ class HttpProtocolClientGeneratorTest {
195185
val op = SdkHttpOperation.build<GetFooStreamingOutputNoInputRequest, GetFooStreamingOutputNoInputResponse> {
196186
serializer = GetFooStreamingOutputNoInputOperationSerializer()
197187
deserializer = GetFooStreamingOutputNoInputOperationDeserializer()
198-
context {
199-
operationName = "GetFooStreamingOutputNoInput"
200-
serviceName = ServiceId
201-
}
188+
operationName = "GetFooStreamingOutputNoInput"
189+
serviceName = ServiceId
202190
telemetry {
203191
provider = config.telemetryProvider
204192
scope = telemetryScope
@@ -218,10 +206,8 @@ class HttpProtocolClientGeneratorTest {
218206
val op = SdkHttpOperation.build<GetFooStreamingInputNoOutputRequest, GetFooStreamingInputNoOutputResponse> {
219207
serializer = GetFooStreamingInputNoOutputOperationSerializer()
220208
deserializer = GetFooStreamingInputNoOutputOperationDeserializer()
221-
context {
222-
operationName = "GetFooStreamingInputNoOutput"
223-
serviceName = ServiceId
224-
}
209+
operationName = "GetFooStreamingInputNoOutput"
210+
serviceName = ServiceId
225211
telemetry {
226212
provider = config.telemetryProvider
227213
scope = telemetryScope
@@ -241,10 +227,8 @@ class HttpProtocolClientGeneratorTest {
241227
val op = SdkHttpOperation.build<GetFooNoRequiredRequest, GetFooNoRequiredResponse> {
242228
serializer = GetFooNoRequiredOperationSerializer()
243229
deserializer = GetFooNoRequiredOperationDeserializer()
244-
context {
245-
operationName = "GetFooNoRequired"
246-
serviceName = ServiceId
247-
}
230+
operationName = "GetFooNoRequired"
231+
serviceName = ServiceId
248232
telemetry {
249233
provider = config.telemetryProvider
250234
scope = telemetryScope
@@ -264,10 +248,8 @@ class HttpProtocolClientGeneratorTest {
264248
val op = SdkHttpOperation.build<GetFooSomeRequiredRequest, GetFooSomeRequiredResponse> {
265249
serializer = GetFooSomeRequiredOperationSerializer()
266250
deserializer = GetFooSomeRequiredOperationDeserializer()
267-
context {
268-
operationName = "GetFooSomeRequired"
269-
serviceName = ServiceId
270-
}
251+
operationName = "GetFooSomeRequired"
252+
serviceName = ServiceId
271253
telemetry {
272254
provider = config.telemetryProvider
273255
scope = telemetryScope
@@ -343,11 +325,9 @@ class HttpProtocolClientGeneratorTest {
343325
val op = SdkHttpOperation.build<GetStatusRequest, GetStatusResponse> {
344326
serializer = GetStatusOperationSerializer()
345327
deserializer = GetStatusOperationDeserializer()
346-
context {
347-
operationName = "GetStatus"
348-
serviceName = ServiceId
349-
hostPrefix = "$prefix"
350-
}
328+
operationName = "GetStatus"
329+
serviceName = ServiceId
330+
hostPrefix = "$prefix"
351331
telemetry {
352332
provider = config.telemetryProvider
353333
scope = telemetryScope

runtime/auth/http-auth-aws/common/test/aws/smithy/kotlin/runtime/http/auth/AwsHttpSignerTestBase.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,9 @@ public abstract class AwsHttpSignerTestBase(
7676
}
7777
}
7878
deserializer = IdentityDeserializer
79-
79+
operationName = "testSigningOperation"
80+
serviceName = "testService"
8081
context {
81-
operationName = "testSigningOperation"
82-
serviceName = "testService"
8382
set(AwsSigningAttributes.SigningRegion, "us-east-1")
8483
set(AwsSigningAttributes.SigningDate, Instant.fromIso8601("2020-10-16T19:56:00Z"))
8584
set(AwsSigningAttributes.SigningService, "demo")

runtime/protocol/aws-json-protocols/common/test/aws/smithy/kotlin/runtime/awsprotocol/json/AwsJsonProtocolTest.kt

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ class AwsJsonProtocolTest {
2626
val op = SdkHttpOperation.build<Unit, HttpResponse> {
2727
serializer = UnitSerializer
2828
deserializer = IdentityDeserializer
29-
context {
30-
operationName = "Bar"
31-
serviceName = "Foo"
32-
}
29+
operationName = "Bar"
30+
serviceName = "Foo"
3331
}
3432
val client = SdkHttpClient(TestEngine())
3533
val m = AwsJsonProtocol("FooService_blah", "1.1")
@@ -49,10 +47,8 @@ class AwsJsonProtocolTest {
4947
val op = SdkHttpOperation.build<Unit, HttpResponse> {
5048
serializer = UnitSerializer
5149
deserializer = IdentityDeserializer
52-
context {
53-
operationName = "Bar"
54-
serviceName = "Foo"
55-
}
50+
operationName = "Bar"
51+
serviceName = "Foo"
5652
}
5753
val client = SdkHttpClient(TestEngine())
5854
op.install(AwsJsonProtocol("FooService", "1.1"))
@@ -75,10 +71,8 @@ class AwsJsonProtocolTest {
7571
}
7672
}
7773
deserializer = IdentityDeserializer
78-
context {
79-
operationName = "Bar"
80-
serviceName = "Foo"
81-
}
74+
operationName = "Bar"
75+
serviceName = "Foo"
8276
}
8377
val client = SdkHttpClient(TestEngine())
8478
op.install(AwsJsonProtocol("FooService", "1.1"))

runtime/protocol/http-client/common/src/aws/smithy/kotlin/runtime/http/operation/HttpOperationContext.kt

Lines changed: 29 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,83 +6,50 @@
66
package aws.smithy.kotlin.runtime.http.operation
77

88
import aws.smithy.kotlin.runtime.InternalApi
9-
import aws.smithy.kotlin.runtime.client.ClientOptionsBuilder
10-
import aws.smithy.kotlin.runtime.client.SdkClientOption
119
import aws.smithy.kotlin.runtime.http.response.HttpCall
1210
import aws.smithy.kotlin.runtime.operation.ExecutionContext
13-
import aws.smithy.kotlin.runtime.util.AttributeKey
14-
import aws.smithy.kotlin.runtime.util.Attributes
15-
import aws.smithy.kotlin.runtime.util.emptyAttributes
11+
import aws.smithy.kotlin.runtime.util.*
1612

1713
/**
1814
* Common configuration for an SDK (HTTP) operation/call
1915
*/
2016
@InternalApi
21-
public open class HttpOperationContext {
22-
@InternalApi
23-
public companion object {
24-
/**
25-
* A prefix to prepend the resolved hostname with.
26-
* See [endpointTrait](https://awslabs.github.io/smithy/1.0/spec/core/endpoint-traits.html#endpoint-trait)
27-
*/
28-
public val HostPrefix: AttributeKey<String> = AttributeKey("aws.smithy.kotlin#HostPrefix")
17+
public object HttpOperationContext {
2918

30-
/**
31-
* The HTTP calls made for this operation (this may be > 1 if for example retries are involved)
32-
*/
33-
public val HttpCallList: AttributeKey<List<HttpCall>> = AttributeKey("aws.smithy.kotlin#HttpCallList")
34-
35-
/**
36-
* The unique request ID generated for tracking the request in-flight client side.
37-
*
38-
* NOTE: This is guaranteed to exist.
39-
*/
40-
public val SdkInvocationId: AttributeKey<String> = AttributeKey("aws.smithy.kotlin#SdkInvocationId")
41-
42-
/**
43-
* The operation input pre-serialization.
44-
*
45-
* NOTE: This is guaranteed to exist after serialization.
46-
*/
47-
public val OperationInput: AttributeKey<Any> = AttributeKey("aws.smithy.kotlin#OperationInput")
48-
49-
/**
50-
* The operation metrics container used by various components to record metrics
51-
*/
52-
public val OperationMetrics: AttributeKey<OperationMetrics> = AttributeKey("aws.smithy.kotlin#OperationMetrics")
53-
54-
/**
55-
* Cached attribute level attributes (e.g. rpc.method, rpc.service, etc)
56-
*/
57-
public val OperationAttributes: AttributeKey<Attributes> = AttributeKey("aws.smithy.kotlin#OperationAttributes")
19+
/**
20+
* A prefix to prepend the resolved hostname with.
21+
* See [endpointTrait](https://awslabs.github.io/smithy/1.0/spec/core/endpoint-traits.html#endpoint-trait)
22+
*/
23+
public val HostPrefix: AttributeKey<String> = AttributeKey("aws.smithy.kotlin#HostPrefix")
5824

59-
/**
60-
* Build this operation into an HTTP [ExecutionContext]
61-
*/
62-
public fun build(block: Builder.() -> Unit): ExecutionContext = Builder().apply(block).build()
63-
}
25+
/**
26+
* The HTTP calls made for this operation (this may be > 1 if for example retries are involved)
27+
*/
28+
public val HttpCallList: AttributeKey<List<HttpCall>> = AttributeKey("aws.smithy.kotlin#HttpCallList")
6429

6530
/**
66-
* Convenience builder for constructing HTTP client operations
31+
* The unique request ID generated for tracking the request in-flight client side.
32+
*
33+
* NOTE: This is guaranteed to exist.
6734
*/
68-
@InternalApi
69-
public open class Builder : ClientOptionsBuilder() {
35+
public val SdkInvocationId: AttributeKey<String> = AttributeKey("aws.smithy.kotlin#SdkInvocationId")
7036

71-
/**
72-
* The name of the operation
73-
*/
74-
public var operationName: String? by requiredOption(SdkClientOption.OperationName)
37+
/**
38+
* The operation input pre-serialization.
39+
*
40+
* NOTE: This is guaranteed to exist after serialization.
41+
*/
42+
public val OperationInput: AttributeKey<Any> = AttributeKey("aws.smithy.kotlin#OperationInput")
7543

76-
/**
77-
* The name of the service the request is sent to
78-
*/
79-
public var serviceName: String? by requiredOption(SdkClientOption.ServiceName)
44+
/**
45+
* The operation metrics container used by various components to record metrics
46+
*/
47+
public val OperationMetrics: AttributeKey<OperationMetrics> = AttributeKey("aws.smithy.kotlin#OperationMetrics")
8048

81-
/**
82-
* (Optional) prefix to prepend to a (resolved) hostname
83-
*/
84-
public var hostPrefix: String? by option(HostPrefix)
85-
}
49+
/**
50+
* Cached attribute level attributes (e.g. rpc.method, rpc.service, etc)
51+
*/
52+
public val OperationAttributes: AttributeKey<Attributes> = AttributeKey("aws.smithy.kotlin#OperationAttributes")
8653
}
8754

8855
internal val ExecutionContext.operationMetrics: OperationMetrics

runtime/protocol/http-client/common/src/aws/smithy/kotlin/runtime/http/operation/SdkHttpOperation.kt

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package aws.smithy.kotlin.runtime.http.operation
77

88
import aws.smithy.kotlin.runtime.InternalApi
9+
import aws.smithy.kotlin.runtime.client.SdkClientOption
910
import aws.smithy.kotlin.runtime.http.HttpHandler
1011
import aws.smithy.kotlin.runtime.http.interceptors.HttpInterceptor
1112
import aws.smithy.kotlin.runtime.http.response.complete
@@ -122,21 +123,41 @@ public class SdkHttpOperationBuilder<I, O> (
122123
public var serializer: HttpSerialize<I>? = null
123124
public var deserializer: HttpDeserialize<O>? = null
124125
public val execution: SdkOperationExecution<I, O> = SdkOperationExecution()
125-
public val context: HttpOperationContext.Builder = HttpOperationContext.Builder()
126+
public val context: ExecutionContext = ExecutionContext()
127+
128+
/**
129+
* The name of the operation
130+
*/
131+
public var operationName: String? = null
132+
133+
/**
134+
* The name of the service the request is sent to
135+
*/
136+
public var serviceName: String? = null
137+
138+
/**
139+
* (Optional) prefix to prepend to a (resolved) hostname
140+
*/
141+
public var hostPrefix: String? = null
126142

127143
public fun build(): SdkHttpOperation<I, O> {
128144
val opSerializer = requireNotNull(serializer) { "SdkHttpOperation.serializer must not be null" }
129145
val opDeserializer = requireNotNull(deserializer) { "SdkHttpOperation.deserializer must not be null" }
146+
requireNotNull(operationName) { "operationName is a required HTTP execution attribute" }
147+
requireNotNull(serviceName) { "serviceName is a required HTTP execution attribute" }
148+
context[SdkClientOption.OperationName] = operationName!!
149+
context[SdkClientOption.ServiceName] = serviceName!!
150+
hostPrefix?.let { context[HttpOperationContext.HostPrefix] = it }
130151
val typeInfo = OperationTypeInfo(inputType, outputType)
131-
return SdkHttpOperation(execution, context.build(), opSerializer, opDeserializer, typeInfo, telemetry)
152+
return SdkHttpOperation(execution, context, opSerializer, opDeserializer, typeInfo, telemetry)
132153
}
133154
}
134155

135156
/**
136157
* Configure HTTP operation context elements
137158
*/
138159
@InternalApi
139-
public inline fun <I, O> SdkHttpOperationBuilder<I, O>.context(block: HttpOperationContext.Builder.() -> Unit) {
160+
public inline fun <I, O> SdkHttpOperationBuilder<I, O>.context(block: ExecutionContext.() -> Unit) {
140161
context.apply(block)
141162
}
142163

0 commit comments

Comments
 (0)