Skip to content

Commit

Permalink
Merge branch 'main' of github.com:smithy-lang/smithy-kotlin into jmes…
Browse files Browse the repository at this point in the history
…path-flatten
  • Loading branch information
lauzadis committed Nov 6, 2024
2 parents 6952cb0 + f0df363 commit b6efb80
Show file tree
Hide file tree
Showing 44 changed files with 615 additions and 83 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/kat-transform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Kat Transform

on:
pull_request:
types: [ opened, synchronize, reopened, labeled, unlabeled ]
branches: [ main ]

# Allow one instance of this workflow per pull request, and cancel older runs when new changes are pushed
concurrency:
group: kat-pr-${{ github.ref }}
cancel-in-progress: true

permissions:
id-token: write
contents: read

env:
RUN: ${{ github.run_id }}-${{ github.run_number }}
GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dkotlin.incremental=false"

jobs:
verify-transform:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
path: 'smithy-kotlin'

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }}
aws-region: us-west-2

- name: Setup kat
uses: awslabs/aws-kotlin-repo-tools/.github/actions/setup-kat@main

- name: Configure JDK
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: 17
cache: 'gradle'

- name: Build
working-directory: ./smithy-kotlin
shell: bash
run: |
pwd
ls -lsa
kat bump-version # Bump from `vNext-SNAPSHOT` to `vNext`. kat transform only works on non-SNAPSHOT versions
kat bump-version --property codegenVersion
./gradlew build
./gradlew publishAllPublicationsToTestLocalRepository
- name: Transform
working-directory: ./smithy-kotlin
shell: bash
run: |
pwd
ls -lsa
kat brazil transform -i ./build/m2 -o ./transformed -t .brazil.json -v live
# Check for manifest file
if [ ! -f "./transformed/brazil-import-manifest.json" ]; then
echo "Error: brazil-import-manifest.json not found in the transformed artifact"
exit 1
fi
echo "Transformation succeeded!"
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## [1.3.19] - 11/05/2024

## [1.3.18] - 10/31/2024

### Fixes
* [#1214](https://github.com/awslabs/aws-sdk-kotlin/issues/1214) Add support for connection idle monitoring for OkHttp via the engine config parameter `connectionIdlePollingInterval`. Monitoring is disabled by default to match previous behavior. This monitoring will switch to enabled by default in an upcoming minor version release.

### Miscellaneous
* Add `Accept` header to all RpcV2Cbor requests
* Correct documentation for `ByteStream.writeToOutputStream`, add `ByteStream.appendToOutputStream`

## [1.3.17] - 10/16/2024

### Miscellaneous
* Upgrade to Kotlin 2.0.21

## [1.3.16] - 10/10/2024

## [1.3.15] - 10/08/2024
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import software.amazon.smithy.model.traits.TimestampFormatTrait
import software.amazon.smithy.model.traits.UnitTypeTrait
import software.amazon.smithy.protocol.traits.Rpcv2CborTrait

private const val ACCEPT_HEADER = "application/cbor"
private const val ACCEPT_HEADER_EVENT_STREAM = "application/vnd.amazon.eventstream"

class RpcV2Cbor : AwsHttpBindingProtocolGenerator() {
override val protocol: ShapeId = Rpcv2CborTrait.ID

Expand Down Expand Up @@ -59,13 +62,16 @@ class RpcV2Cbor : AwsHttpBindingProtocolGenerator() {
}
}

// Requests with event stream responses MUST include an `Accept` header set to the value `application/vnd.amazon.eventstream`
val eventStreamsAcceptHeaderMiddleware = object : ProtocolMiddleware {
private val mutateHeadersMiddleware = MutateHeadersMiddleware(extraHeaders = mapOf("Accept" to "application/vnd.amazon.eventstream"))

override fun isEnabledFor(ctx: ProtocolGenerator.GenerationContext, op: OperationShape): Boolean = op.isOutputEventStream(ctx.model)
override val name: String = "RpcV2CborEventStreamsAcceptHeaderMiddleware"
override fun render(ctx: ProtocolGenerator.GenerationContext, op: OperationShape, writer: KotlinWriter) = mutateHeadersMiddleware.render(ctx, op, writer)
// Add `Accept` header with value `application/cbor` for standard responses
// and `application/vnd.amazon.eventstream` for event stream responses
val acceptHeaderMiddleware = object : ProtocolMiddleware {
override val name: String = "RpcV2CborAcceptHeaderMiddleware"
override fun render(ctx: ProtocolGenerator.GenerationContext, op: OperationShape, writer: KotlinWriter) {
val acceptHeaderValue = if (op.isOutputEventStream(ctx.model)) ACCEPT_HEADER_EVENT_STREAM else ACCEPT_HEADER
MutateHeadersMiddleware(
extraHeaders = mapOf("Accept" to acceptHeaderValue),
).render(ctx, op, writer)
}
}

// Emit a metric to track usage of RpcV2Cbor
Expand All @@ -79,7 +85,7 @@ class RpcV2Cbor : AwsHttpBindingProtocolGenerator() {
return super.getDefaultHttpMiddleware(ctx) + listOf(
smithyProtocolHeaderMiddleware,
validateSmithyProtocolHeaderMiddleware,
eventStreamsAcceptHeaderMiddleware,
acceptHeaderMiddleware,
businessMetricsMiddleware,
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package software.amazon.smithy.kotlin.codegen.aws.protocols

import software.amazon.smithy.kotlin.codegen.test.*
import kotlin.test.Test

class RpcV2CborTest {
val model = """
${"$"}version: "2"
namespace com.test
use smithy.protocols#rpcv2Cbor
use aws.api#service
@rpcv2Cbor
@service(sdkId: "CborExample")
service CborExample {
version: "1.0.0",
operations: [GetFoo, GetFooStreaming]
}
@http(method: "POST", uri: "/foo")
operation GetFoo {}
@http(method: "POST", uri: "/foo-streaming")
operation GetFooStreaming {
input := {}
output := {
events: FooEvents
}
}
// Model taken from https://smithy.io/2.0/spec/streaming.html#event-streams
@streaming
union FooEvents {
up: Movement
down: Movement
left: Movement
right: Movement
throttlingError: ThrottlingError
}
structure Movement {
velocity: Float
}
@error("client")
@retryable(throttling: true)
structure ThrottlingError {}
""".toSmithyModel()

@Test
fun testStandardAcceptHeader() {
val ctx = model.newTestContext("CborExample")

val generator = RpcV2Cbor()
generator.generateProtocolClient(ctx.generationCtx)

ctx.generationCtx.delegator.finalize()
ctx.generationCtx.delegator.flushWriters()

val actual = ctx.manifest.expectFileString("/src/main/kotlin/com/test/DefaultTestClient.kt")
val getFooMethod = actual.lines(" override suspend fun getFoo(input: GetFooRequest): GetFooResponse {", " }")

val expectedHeaderMutation = """
op.install(
MutateHeaders().apply {
append("Accept", "application/cbor")
}
)
""".replaceIndent(" ")
getFooMethod.shouldContainOnlyOnceWithDiff(expectedHeaderMutation)
}

@Test
fun testEventStreamAcceptHeader() {
val ctx = model.newTestContext("CborExample")

val generator = RpcV2Cbor()
generator.generateProtocolClient(ctx.generationCtx)

ctx.generationCtx.delegator.finalize()
ctx.generationCtx.delegator.flushWriters()

val actual = ctx.manifest.expectFileString("/src/main/kotlin/com/test/DefaultTestClient.kt")
val getFooMethod = actual.lines(" override suspend fun <T> getFooStreaming(input: GetFooStreamingRequest, block: suspend (GetFooStreamingResponse) -> T): T {", " }")

val expectedHeaderMutation = """
op.install(
MutateHeaders().apply {
append("Accept", "application/vnd.amazon.eventstream")
}
)
""".replaceIndent(" ")
getFooMethod.shouldContainOnlyOnceWithDiff(expectedHeaderMutation)
}
}
1 change: 0 additions & 1 deletion codegen/smithy-kotlin-codegen-testutils/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ group = "software.amazon.smithy.kotlin"
version = codegenVersion

dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(libs.smithy.aws.traits)
implementation(libs.smithy.protocol.traits)
api(project(":codegen:smithy-kotlin-codegen"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import software.amazon.smithy.model.traits.TimestampFormatTrait
import software.amazon.smithy.model.traits.Trait
import software.amazon.smithy.protocol.traits.Rpcv2CborTrait
import software.amazon.smithy.utils.StringUtils
import kotlin.test.assertNotEquals

// This file houses test classes and functions relating to the code generator (protocols, serializers, etc)
// Items contained here should be relatively high-level, utilizing all members of codegen classes, Smithy, and
Expand Down Expand Up @@ -274,3 +275,19 @@ fun KotlinCodegenPlugin.Companion.createSymbolProvider(
* create a new [KotlinWriter] using the test context package name
*/
fun TestContext.newWriter(): KotlinWriter = KotlinWriter(generationCtx.settings.pkg.name)

/**
* Get all the lines between [fromLine] and [toLine]
*/
fun String.lines(fromLine: String, toLine: String): String {
val allLines = lines()

val fromIdx = allLines.indexOf(fromLine)
assertNotEquals(-1, fromIdx, """Could not find from line "$fromLine" in all lines""")

val toIdxOffset = allLines.drop(fromIdx + 1).indexOf(toLine)
assertNotEquals(-1, toIdxOffset, """Could not find to line "$toLine" in all lines""")

val toIdx = toIdxOffset + fromIdx + 1
return allLines.subList(fromIdx, toIdx + 1).joinToString("\n")
}
1 change: 0 additions & 1 deletion codegen/smithy-kotlin-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ val sdkVersion: String by project
val runtimeVersion = sdkVersion

dependencies {
implementation(kotlin("stdlib-jdk8"))
api(libs.smithy.codegen.core)
api(libs.smithy.waiters)
implementation(libs.smithy.rules.engine)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ Neptune,Neptune
neptunedata,Neptunedata
Network Firewall,NetworkFirewall
NetworkManager,NetworkManager
nimble,Nimble
OAM,Oam
Omics,Omics
OpenSearch,OpenSearch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ Neptune
neptunedata
Network Firewall
NetworkManager
nimble
OAM
Omics
OpenSearch
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ kotlinx.atomicfu.enableNativeIrTransformation=false
org.gradle.jvmargs=-Xmx2G -XX:MaxMetaspaceSize=1G

# SDK
sdkVersion=1.3.17-SNAPSHOT
sdkVersion=1.3.20-SNAPSHOT

# codegen
codegenVersion=0.33.17-SNAPSHOT
codegenVersion=0.33.20-SNAPSHOT
32 changes: 16 additions & 16 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
[versions]
kotlin-version = "2.0.10"
kotlin-version = "2.0.21"
dokka-version = "1.9.10"

aws-kotlin-repo-tools-version = "0.4.10"
aws-kotlin-repo-tools-version = "0.4.13"

# libs
coroutines-version = "1.9.0"
atomicfu-version = "0.24.0"
atomicfu-version = "0.25.0"
okhttp-version = "5.0.0-alpha.14"
okhttp4-version = "4.12.0"
okio-version = "3.9.0"
otel-version = "1.32.0"
slf4j-version = "2.0.9"
okio-version = "3.9.1"
otel-version = "1.43.0"
slf4j-version = "2.0.16"
slf4j-v1x-version = "1.7.36"
crt-kotlin-version = "0.8.9"
micrometer-version = "1.13.2"
crt-kotlin-version = "0.8.10"
micrometer-version = "1.13.6"

# codegen
smithy-version = "1.51.0"
smithy-gradle-version = "0.9.0"

# testing
junit-version = "5.10.1"
kotest-version = "5.8.0"
junit-version = "5.10.5"
kotest-version = "5.9.1"
kotlin-compile-testing-version = "1.6.0"
kotlinx-benchmark-version = "0.4.9"
kotlinx-serialization-version = "1.6.0"
docker-java-version = "3.3.6"
ktor-version = "2.3.12"
kotlinx-benchmark-version = "0.4.12"
kotlinx-serialization-version = "1.7.3"
docker-java-version = "3.4.0"
ktor-version = "3.0.0"
kaml-version = "0.55.0"
jsoup-version = "1.16.2"
jsoup-version = "1.18.1"

[libraries]
aws-kotlin-repo-tools-build-support = { module="aws.sdk.kotlin.gradle:build-support", version.ref = "aws-kotlin-repo-tools-version" }
Expand Down Expand Up @@ -92,7 +92,7 @@ ktor-http-cio = { module = "io.ktor:ktor-http-cio", version.ref = "ktor-version"
ktor-utils = { module = "io.ktor:ktor-utils", version.ref = "ktor-version" }
ktor-io = { module = "io.ktor:ktor-io", version.ref = "ktor-version" }
ktor-server-netty = { module = "io.ktor:ktor-server-netty", version.ref = "ktor-version" }
ktor-server-jetty = { module = "io.ktor:ktor-server-jetty", version.ref = "ktor-version" }
ktor-server-jetty-jakarta = { module = "io.ktor:ktor-server-jetty-jakarta", version.ref = "ktor-version" }
ktor-server-cio = { module = "io.ktor:ktor-server-cio", version.ref = "ktor-version" }
ktor-network-tls-certificates = { module = "io.ktor:ktor-network-tls-certificates", version.ref = "ktor-version" }

Expand Down
6 changes: 6 additions & 0 deletions runtime/auth/aws-credentials/api/aws-credentials.api
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ public final class aws/smithy/kotlin/runtime/auth/awscredentials/CachedCredentia
public synthetic fun <init> (Laws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProvider;JJLaws/smithy/kotlin/runtime/time/Clock;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun close ()V
public fun resolve (Laws/smithy/kotlin/runtime/collections/Attributes;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun toString ()Ljava/lang/String;
}

public final class aws/smithy/kotlin/runtime/auth/awscredentials/CachedCredentialsProviderKt {
Expand Down Expand Up @@ -45,6 +46,7 @@ public final class aws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProv
public fun <init> (Ljava/util/List;)V
public fun <init> ([Laws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProvider;)V
public fun resolve (Laws/smithy/kotlin/runtime/collections/Attributes;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun toString ()Ljava/lang/String;
}

public abstract interface class aws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProviderConfig {
Expand All @@ -61,6 +63,10 @@ public final class aws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProv
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/Throwable;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
}

public final class aws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProviderKt {
public static final fun getSimpleClassName (Laws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProvider;)Ljava/lang/String;
}

public abstract interface class aws/smithy/kotlin/runtime/auth/awscredentials/SigV4aClientConfig {
public abstract fun getSigV4aSigningRegionSet ()Ljava/util/Set;
}
Expand Down
Loading

0 comments on commit b6efb80

Please sign in to comment.