Skip to content

Commit ebb52d4

Browse files
authored
refactor: relocate endpoints, document type, and credential provider util types (#806)
1 parent 7babb88 commit ebb52d4

File tree

44 files changed

+711
-119
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+711
-119
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"id": "88c3a8ce-5e7b-4754-96d3-42c4de1fcddd",
3+
"type": "misc",
4+
"description": "Refactor: move `EndpointProvider` out of http package into `aws.smithy.kotlin.runtime.client.endpoints`"
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"id": "90312c67-354c-426d-bd15-b4f5901a3da5",
3+
"type": "misc",
4+
"description": "Refactor: relocate `CachedCredentialsProvider` and `CredentialsProviderChain` from `aws-sdk-kotlin`"
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"id": "91436071-ff83-4476-aa11-35ea73e255c7",
3+
"type": "misc",
4+
"description": "Refactor: move `Document` type to `aws.smithy.kotlin.runtime.content` package"
5+
}

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/core/KotlinSymbolProvider.kt

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,22 +204,13 @@ class KotlinSymbolProvider(private val model: Model, private val settings: Kotli
204204
}
205205

206206
override fun blobShape(shape: BlobShape): Symbol = if (shape.hasTrait<StreamingTrait>()) {
207-
val dependency = KotlinDependency.CORE
208-
createSymbolBuilder(shape, "ByteStream", boxed = true)
209-
.namespace("${dependency.namespace}.content", ".")
210-
.addDependency(dependency)
211-
.build()
207+
RuntimeTypes.Core.Content.ByteStream.asNullable()
212208
} else {
213209
createSymbolBuilder(shape, "ByteArray", boxed = true, namespace = "kotlin").build()
214210
}
215211

216-
override fun documentShape(shape: DocumentShape?): Symbol {
217-
val dependency = KotlinDependency.CORE
218-
return createSymbolBuilder(shape, "Document", boxed = true)
219-
.namespace("${dependency.namespace}.smithy", ".")
220-
.addDependency(dependency)
221-
.build()
222-
}
212+
override fun documentShape(shape: DocumentShape?): Symbol =
213+
RuntimeTypes.Core.Content.Document.asNullable()
223214

224215
override fun unionShape(shape: UnionShape): Symbol {
225216
val name = shape.defaultName(service)

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/core/RuntimeTypes.kt

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ object RuntimeTypes {
5252
val MutateHeadersMiddleware = symbol("MutateHeaders")
5353
val RetryMiddleware = symbol("RetryMiddleware")
5454
val ResolveEndpoint = symbol("ResolveEndpoint")
55+
val setResolvedEndpoint = symbol("setResolvedEndpoint")
5556
}
5657

5758
object Operation : RuntimeTypePackage(KotlinDependency.HTTP, "operation") {
@@ -67,21 +68,6 @@ object RuntimeTypes {
6768
val InlineMiddleware = symbol("InlineMiddleware")
6869
}
6970

70-
object Endpoints : RuntimeTypePackage(KotlinDependency.HTTP, "endpoints") {
71-
val EndpointProvider = symbol("EndpointProvider")
72-
val Endpoint = symbol("Endpoint")
73-
val EndpointProviderException = symbol("EndpointProviderException")
74-
val setResolvedEndpoint = symbol("setResolvedEndpoint")
75-
76-
object Functions : RuntimeTypePackage(KotlinDependency.HTTP, "endpoints.functions") {
77-
val substring = symbol("substring")
78-
val isValidHostLabel = symbol("isValidHostLabel")
79-
val uriEncode = symbol("uriEncode")
80-
val parseUrl = symbol("parseUrl")
81-
val Url = symbol("Url")
82-
}
83-
}
84-
8571
object Config : RuntimeTypePackage(KotlinDependency.HTTP, "config") {
8672
val HttpClientConfig = symbol("HttpClientConfig")
8773
}
@@ -111,9 +97,11 @@ object RuntimeTypes {
11197
object Content : RuntimeTypePackage(KotlinDependency.CORE, "content") {
11298
val ByteArrayContent = symbol("ByteArrayContent")
11399
val ByteStream = symbol("ByteStream")
100+
val buildDocument = symbol("buildDocument")
101+
val decodeToString = symbol("decodeToString")
102+
val Document = symbol("Document")
114103
val StringContent = symbol("StringContent")
115104
val toByteArray = symbol("toByteArray")
116-
val decodeToString = symbol("decodeToString")
117105
}
118106

119107
object Retries : RuntimeTypePackage(KotlinDependency.CORE, "retries") {
@@ -144,10 +132,6 @@ object RuntimeTypes {
144132
}
145133
}
146134

147-
object Smithy : RuntimeTypePackage(KotlinDependency.CORE, "smithy") {
148-
val Document = symbol("Document")
149-
val buildDocument = symbol("buildDocument")
150-
}
151135

152136
object Hashing : RuntimeTypePackage(KotlinDependency.CORE, "hashing") {
153137
val Sha256 = symbol("Sha256")
@@ -192,6 +176,19 @@ object RuntimeTypes {
192176
val IdempotencyTokenProvider = symbol("IdempotencyTokenProvider")
193177
val IdempotencyTokenConfig = symbol("IdempotencyTokenConfig")
194178
val IdempotencyTokenProviderExt = symbol("idempotencyTokenProvider")
179+
180+
object Endpoints : RuntimeTypePackage(KotlinDependency.SMITHY_CLIENT, "endpoints") {
181+
val EndpointProvider = symbol("EndpointProvider")
182+
val Endpoint = symbol("Endpoint")
183+
val EndpointProviderException = symbol("EndpointProviderException")
184+
object Functions : RuntimeTypePackage(KotlinDependency.SMITHY_CLIENT, "endpoints.functions") {
185+
val substring = symbol("substring")
186+
val isValidHostLabel = symbol("isValidHostLabel")
187+
val uriEncode = symbol("uriEncode")
188+
val parseUrl = symbol("parseUrl")
189+
val Url = symbol("Url")
190+
}
191+
}
195192
}
196193

197194
object Serde : RuntimeTypePackage(KotlinDependency.SERDE) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class ShapeValueGenerator(
138138
override fun objectNode(node: ObjectNode) {
139139
if (currShape.type == ShapeType.DOCUMENT) {
140140
writer
141-
.writeInline("#T {\n", RuntimeTypes.Core.Smithy.buildDocument)
141+
.writeInline("#T {\n", RuntimeTypes.Core.Content.buildDocument)
142142
.indent()
143143
}
144144

@@ -215,7 +215,7 @@ class ShapeValueGenerator(
215215
writer.writeInline("#L", "$symbolName.$symbolMember")
216216
}
217217

218-
ShapeType.DOCUMENT -> writer.writeInline("#T(#S)", RuntimeTypes.Core.Smithy.Document, node.value)
218+
ShapeType.DOCUMENT -> writer.writeInline("#T(#S)", RuntimeTypes.Core.Content.Document, node.value)
219219

220220
else -> writer.writeInline("#S", node.value)
221221
}
@@ -228,7 +228,7 @@ class ShapeValueGenerator(
228228
override fun arrayNode(node: ArrayNode) {
229229
when (currShape.type) {
230230
ShapeType.DOCUMENT -> {
231-
writer.withInlineBlock("#T(", ")", RuntimeTypes.Core.Smithy.Document) {
231+
writer.withInlineBlock("#T(", ")", RuntimeTypes.Core.Content.Document) {
232232
writer.withInlineBlock("listOf(", ")") {
233233
node.elements.forEach {
234234
generator.writeShapeValueInline(writer, currShape, it)
@@ -275,7 +275,7 @@ class ShapeValueGenerator(
275275

276276
ShapeType.DOCUMENT -> writer.writeInline(
277277
"#T(#L#L)",
278-
RuntimeTypes.Core.Smithy.Document,
278+
RuntimeTypes.Core.Content.Document,
279279
node.value,
280280
if (node.isFloatingPointNumber) "F" else "L",
281281
)
@@ -286,7 +286,7 @@ class ShapeValueGenerator(
286286

287287
override fun booleanNode(node: BooleanNode) {
288288
when (currShape.type) {
289-
ShapeType.DOCUMENT -> writer.writeInline("#T(#L)", RuntimeTypes.Core.Smithy.Document, node.value)
289+
ShapeType.DOCUMENT -> writer.writeInline("#T(#L)", RuntimeTypes.Core.Content.Document, node.value)
290290
ShapeType.BOOLEAN -> writer.writeInline("#L", if (node.value) "true" else "false")
291291
else -> throw CodegenException("unexpected shape type $currShape for boolean value")
292292
}

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/endpoints/DefaultEndpointProviderGenerator.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ import software.amazon.smithy.rulesengine.language.visit.TemplateVisitor
3030
* The core set of standard library functions available to the rules language.
3131
*/
3232
internal val coreFunctions: Map<String, Symbol> = mapOf(
33-
"substring" to RuntimeTypes.HttpClient.Endpoints.Functions.substring,
34-
"isValidHostLabel" to RuntimeTypes.HttpClient.Endpoints.Functions.isValidHostLabel,
35-
"uriEncode" to RuntimeTypes.HttpClient.Endpoints.Functions.uriEncode,
36-
"parseURL" to RuntimeTypes.HttpClient.Endpoints.Functions.parseUrl,
33+
"substring" to RuntimeTypes.SmithyClient.Endpoints.Functions.substring,
34+
"isValidHostLabel" to RuntimeTypes.SmithyClient.Endpoints.Functions.isValidHostLabel,
35+
"uriEncode" to RuntimeTypes.SmithyClient.Endpoints.Functions.uriEncode,
36+
"parseURL" to RuntimeTypes.SmithyClient.Endpoints.Functions.parseUrl,
3737
)
3838

3939
/**
@@ -98,11 +98,11 @@ class DefaultEndpointProviderGenerator(
9898
"public override suspend fun resolveEndpoint(params: #T): #T {",
9999
"}",
100100
paramsSymbol,
101-
RuntimeTypes.HttpClient.Endpoints.Endpoint,
101+
RuntimeTypes.SmithyClient.Endpoints.Endpoint,
102102
) {
103103
rules.rules.forEach(::renderRule)
104104
write("")
105-
write("throw #T(\"endpoint rules were exhausted without a match\")", RuntimeTypes.HttpClient.Endpoints.EndpointProviderException)
105+
write("throw #T(\"endpoint rules were exhausted without a match\")", RuntimeTypes.SmithyClient.Endpoints.EndpointProviderException)
106106
}
107107
}
108108

@@ -145,7 +145,7 @@ class DefaultEndpointProviderGenerator(
145145

146146
private fun renderEndpointRule(rule: EndpointRule) {
147147
withConditions(rule.conditions) {
148-
writer.withBlock("return #T(", ")", RuntimeTypes.HttpClient.Endpoints.Endpoint) {
148+
writer.withBlock("return #T(", ")", RuntimeTypes.SmithyClient.Endpoints.Endpoint) {
149149
writeInline("#T.parse(", RuntimeTypes.Core.Net.Url)
150150
renderExpression(rule.endpoint.url)
151151
write("),")
@@ -189,7 +189,7 @@ class DefaultEndpointProviderGenerator(
189189

190190
private fun renderErrorRule(rule: ErrorRule) {
191191
withConditions(rule.conditions) {
192-
writer.writeInline("throw #T(", RuntimeTypes.HttpClient.Endpoints.EndpointProviderException)
192+
writer.writeInline("throw #T(", RuntimeTypes.SmithyClient.Endpoints.EndpointProviderException)
193193
renderExpression(rule.error)
194194
writer.write(")")
195195
}
@@ -280,7 +280,7 @@ class ExpressionGenerator(
280280
}
281281

282282
override fun visitRecord(value: MutableMap<Identifier, Literal>) {
283-
writer.withInlineBlock("#T {", "}", RuntimeTypes.Core.Smithy.buildDocument) {
283+
writer.withInlineBlock("#T {", "}", RuntimeTypes.Core.Content.buildDocument) {
284284
value.entries.forEachIndexed { index, (k, v) ->
285285
writeInline("#S to ", k.asString())
286286
v.accept(this@ExpressionGenerator as Literal.Vistor<Unit>)

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/endpoints/DefaultEndpointProviderTestGenerator.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class DefaultEndpointProviderTestGenerator(
9494

9595
private fun renderTestCaseExpectation(case: EndpointTestCase) {
9696
if (case.expect.error.isPresent) {
97-
writer.withBlock("val ex = assertFailsWith<#T> {", "}", RuntimeTypes.HttpClient.Endpoints.EndpointProviderException) {
97+
writer.withBlock("val ex = assertFailsWith<#T> {", "}", RuntimeTypes.SmithyClient.Endpoints.EndpointProviderException) {
9898
write("#T().resolveEndpoint(params)", providerSymbol)
9999
}
100100
writer.write("assertEquals(#S, ex.message)", case.expect.error.get())
@@ -105,7 +105,7 @@ class DefaultEndpointProviderTestGenerator(
105105
CodegenException("endpoint test case has neither an expected error nor endpoint")
106106
}
107107

108-
writer.withBlock("val expected = #T(", ")", RuntimeTypes.HttpClient.Endpoints.Endpoint) {
108+
writer.withBlock("val expected = #T(", ")", RuntimeTypes.SmithyClient.Endpoints.Endpoint) {
109109
write("uri = #T.parse(#S),", RuntimeTypes.Core.Net.Url, endpoint.url)
110110

111111
if (endpoint.headers.isNotEmpty()) {

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/endpoints/EndpointProviderGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class EndpointProviderGenerator(
3131

3232
fun render() {
3333
renderDocumentation()
34-
writer.write("public typealias EndpointProvider = #T<#T>", RuntimeTypes.HttpClient.Endpoints.EndpointProvider, paramsSymbol)
34+
writer.write("public typealias EndpointProvider = #T<#T>", RuntimeTypes.SmithyClient.Endpoints.EndpointProvider, paramsSymbol)
3535
}
3636

3737
private fun renderDocumentation() {

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/endpoints/ResolveEndpointMiddlewareGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class ResolveEndpointMiddlewareGenerator(
8484
write("#T.#T<$CLASS_NAME<*>>{ \"resolved endpoint: \$endpoint\" }", RuntimeTypes.KotlinCoroutines.coroutineContext, RuntimeTypes.Tracing.Core.debug)
8585
write("val reqBuilder = context.protocolRequest.#T()", RuntimeTypes.Http.Request.toBuilder)
8686
write("val req = #T(context.executionContext, reqBuilder)", RuntimeTypes.HttpClient.Operation.SdkHttpRequest)
87-
write("#T(req, endpoint)", RuntimeTypes.HttpClient.Endpoints.setResolvedEndpoint)
87+
write("#T(req, endpoint)", RuntimeTypes.HttpClient.Middleware.setResolvedEndpoint)
8888
renderPostResolution()
8989
write("return req.subject.build()")
9090
}

0 commit comments

Comments
 (0)