Skip to content

Commit 082670c

Browse files
authored
feat: k/n http bindings (#97)
1 parent 9908822 commit 082670c

36 files changed

+1142
-252
lines changed

.github/scripts/run-container-test.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,20 @@ def run_docker_test(opts):
101101
'run',
102102
'--rm',
103103
f'-v{test_bin_dir}:/test',
104-
'-w/test',
105-
'-e DEBIAN_FRONTEND=noninteractive',
106-
'--platform',
107-
platform,
108-
image_name,
109-
path_to_exe,
110104
]
105+
if not opts.no_system_certs:
106+
cmd.append(f'-v/etc/ssl:/etc/ssl')
107+
108+
cmd.extend(
109+
[
110+
'-w/test',
111+
'-e DEBIAN_FRONTEND=noninteractive',
112+
'--platform',
113+
platform,
114+
image_name,
115+
path_to_exe,
116+
]
117+
)
111118

112119
cmd = shlex.join(cmd)
113120
print(cmd)
@@ -126,6 +133,7 @@ def create_cli():
126133
parser.add_argument("--distro", required=True, choices=DISTRO_TO_IMAGE_NAME.keys(), help="the distribution name to run the task on")
127134
parser.add_argument("--arch", required=True, choices=DOCKER_PLATFORM_BY_ARCH.keys(), help="the architecture to use")
128135
parser.add_argument("--test-bin-dir", required=True, help="the path to the test binary directory root")
136+
parser.add_argument("--no-system-certs", action='store_true', help="disable mounting system certificates into the container")
129137

130138
return parser
131139

.github/workflows/ci.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
name: CI
22

33
on:
4-
push:
5-
branches:
6-
- '*'
7-
- '!main'
4+
pull_request:
5+
workflow_dispatch:
86

97
env:
108
PACKAGE_NAME: aws-crt-kotlin

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,27 @@ This project is licensed under the Apache-2.0 License.
1616
CRT interfaces are subject to change.
1717

1818
### Linux/Unix
19-
Install some version of libcrypto on which s2n depends. See the [s2n](https://github.com/awslabs/s2n) documentation.
19+
20+
#### Testing Different Linux Distros and Architectures
21+
22+
1. Build the test executable(s) for the architecture(s) you want to test.
2023

2124
```sh
22-
apt-get install libssl-dev
25+
# build everything
26+
./gradlew linuxTestBinaries
27+
28+
# build specific arch
29+
./gradlew linuxX64TestBinaries
2330
```
2431

25-
OR
32+
2. Use the `run-container-test.py` helper script to execute tests locally
2633

2734
```sh
28-
yum install openssl-devel
35+
OCI_EXE=docker python3 .github/scripts/run-container-test.py --distro al2 --arch x64 --test-bin-dir ./aws-crt-kotlin/build/bin
2936
```
3037

31-
Set the path to `libcrypto.a` either as a command line argument to gradle `-PlibcryptoPath=PATH` or in your `local.properties` file.
38+
39+
See the usage/help for different distributions provided: `python3 .github/scripts/run-container.py -h`
3240

3341

3442
### OSX

aws-crt-kotlin/api/android/aws-crt-kotlin.api

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ public final class aws/sdk/kotlin/crt/Config {
3232
}
3333

3434
public class aws/sdk/kotlin/crt/CrtRuntimeException : java/lang/RuntimeException {
35-
public fun <init> (Ljava/lang/String;)V
36-
public fun getErrorCode ()I
35+
public fun <init> ()V
36+
public fun <init> (Ljava/lang/String;Ljava/lang/Throwable;Ljava/lang/Integer;)V
37+
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/Throwable;Ljava/lang/Integer;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
38+
public final fun getErrorCode ()I
3739
public final fun getErrorDescription ()Ljava/lang/String;
3840
public final fun getErrorName ()Ljava/lang/String;
41+
public fun getMessage ()Ljava/lang/String;
3942
}
4043

4144
public final class aws/sdk/kotlin/crt/LogDestination : java/lang/Enum {
@@ -502,7 +505,6 @@ public final class aws/sdk/kotlin/crt/http/HttpClientConnectionManagerOptionsBui
502505

503506
public final class aws/sdk/kotlin/crt/http/HttpException : aws/sdk/kotlin/crt/CrtRuntimeException {
504507
public fun <init> (I)V
505-
public fun getErrorCode ()I
506508
}
507509

508510
public final class aws/sdk/kotlin/crt/http/HttpHeader {
@@ -647,7 +649,7 @@ public abstract interface class aws/sdk/kotlin/crt/http/HttpStream : aws/sdk/kot
647649
public abstract fun activate ()V
648650
public abstract fun getResponseStatusCode ()I
649651
public abstract fun incrementWindow (I)V
650-
public abstract fun writeChunk ([BZ)V
652+
public abstract fun writeChunk ([BZLkotlin/coroutines/Continuation;)Ljava/lang/Object;
651653
}
652654

653655
public final class aws/sdk/kotlin/crt/http/HttpStreamMetrics {

aws-crt-kotlin/api/jvm/aws-crt-kotlin.api

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ public final class aws/sdk/kotlin/crt/Config {
3232
}
3333

3434
public class aws/sdk/kotlin/crt/CrtRuntimeException : java/lang/RuntimeException {
35-
public fun <init> (Ljava/lang/String;)V
36-
public fun getErrorCode ()I
35+
public fun <init> ()V
36+
public fun <init> (Ljava/lang/String;Ljava/lang/Throwable;Ljava/lang/Integer;)V
37+
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/Throwable;Ljava/lang/Integer;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
38+
public final fun getErrorCode ()I
3739
public final fun getErrorDescription ()Ljava/lang/String;
3840
public final fun getErrorName ()Ljava/lang/String;
41+
public fun getMessage ()Ljava/lang/String;
3942
}
4043

4144
public final class aws/sdk/kotlin/crt/LogDestination : java/lang/Enum {
@@ -502,7 +505,6 @@ public final class aws/sdk/kotlin/crt/http/HttpClientConnectionManagerOptionsBui
502505

503506
public final class aws/sdk/kotlin/crt/http/HttpException : aws/sdk/kotlin/crt/CrtRuntimeException {
504507
public fun <init> (I)V
505-
public fun getErrorCode ()I
506508
}
507509

508510
public final class aws/sdk/kotlin/crt/http/HttpHeader {
@@ -647,7 +649,7 @@ public abstract interface class aws/sdk/kotlin/crt/http/HttpStream : aws/sdk/kot
647649
public abstract fun activate ()V
648650
public abstract fun getResponseStatusCode ()I
649651
public abstract fun incrementWindow (I)V
650-
public abstract fun writeChunk ([BZ)V
652+
public abstract fun writeChunk ([BZLkotlin/coroutines/Continuation;)Ljava/lang/Object;
651653
}
652654

653655
public final class aws/sdk/kotlin/crt/http/HttpStreamMetrics {

aws-crt-kotlin/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import aws.sdk.kotlin.gradle.kmp.IDEA_ACTIVE
1111
import aws.sdk.kotlin.gradle.kmp.configureKmpTargets
1212
import aws.sdk.kotlin.gradle.util.typedProp
1313
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
14-
import org.jetbrains.kotlin.konan.target.KonanTarget
1514

1615
plugins {
1716
alias(libs.plugins.kotlin.multiplatform)
@@ -192,6 +191,7 @@ tasks.register("linuxTestBinaries") {
192191

193192
val disableCrossCompile = typedProp<Boolean>("aws.sdk.kotlin.crt.disableCrossCompile") == true
194193
if (disableCrossCompile) {
194+
logger.warn("aws.sdk.kotlin.crt.disableCrossCompile=true: Cross compilation is disabled.")
195195
disableCrossCompileTargets()
196196
}
197197

aws-crt-kotlin/common/src/aws/sdk/kotlin/crt/CrtRuntimeException.kt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,28 @@
55

66
package aws.sdk.kotlin.crt
77

8-
public open class CrtRuntimeException(message: String?) : RuntimeException(message) {
9-
public open val errorCode: Int = CRT.lastError()
8+
public open class CrtRuntimeException(
9+
message: String? = null,
10+
cause: Throwable? = null,
11+
ec: Int? = null,
12+
) : RuntimeException(message, cause) {
13+
14+
public val errorCode: Int = ec ?: CRT.lastError()
15+
16+
override val message: String?
17+
get() = buildString {
18+
if (super.message != null) {
19+
append(super.message)
20+
append(" ")
21+
}
22+
append("ErrorCode: $errorCode")
23+
errorName?.let {
24+
append("; ErrorName: $it")
25+
}
26+
errorDescription?.let {
27+
append("; ErrorDescription: $it")
28+
}
29+
}
1030

1131
public val errorName: String?
1232
get() = CRT.errorName(errorCode)

aws-crt-kotlin/common/src/aws/sdk/kotlin/crt/http/HttpException.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package aws.sdk.kotlin.crt.http
77

8-
import aws.sdk.kotlin.crt.CRT
98
import aws.sdk.kotlin.crt.CrtRuntimeException
109

11-
public class HttpException(override val errorCode: Int) : CrtRuntimeException(CRT.errorString(errorCode))
10+
public class HttpException(ec: Int) : CrtRuntimeException(ec = ec)

aws-crt-kotlin/common/src/aws/sdk/kotlin/crt/http/HttpStream.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ public interface HttpStream : Closeable {
4646
* @param chunkData the chunk of data to send. this should be already formatted in the chunked transfer encoding.
4747
* @param isFinalChunk represents if the chunk of data is the final chunk. if set to true, this will terminate the request stream.
4848
*/
49-
public fun writeChunk(chunkData: ByteArray, isFinalChunk: Boolean)
49+
public suspend fun writeChunk(chunkData: ByteArray, isFinalChunk: Boolean)
5050
}

aws-crt-kotlin/common/test/aws/sdk/kotlin/crt/http/HttpClientConnectionTest.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ package aws.sdk.kotlin.crt.http
88
import aws.sdk.kotlin.crt.CrtTest
99
import aws.sdk.kotlin.crt.io.*
1010
import aws.sdk.kotlin.crt.use
11-
import kotlinx.coroutines.test.runTest
11+
import kotlinx.coroutines.runBlocking
1212
import kotlinx.coroutines.withTimeout
1313
import kotlin.test.*
1414
import kotlin.time.measureTime
1515

1616
class HttpClientConnectionTest : CrtTest() {
17-
@Ignore // FIXME Enable when Kotlin/Native implementation is complete
1817
@Test
19-
fun testDefaults() = runTest {
18+
fun testDefaults(): Unit = runBlocking {
2019
val uri = Uri.parse("https://aws-crt-test-stuff.s3.amazonaws.com")
2120
val socketOpts = SocketOptions()
2221
val elg = EventLoopGroup()
@@ -54,9 +53,8 @@ class HttpClientConnectionTest : CrtTest() {
5453
println("exiting test")
5554
}
5655

57-
@Ignore // FIXME Enable when Kotlin/Native implementation is complete
5856
@Test
59-
fun testHttpConnection() = runTest {
57+
fun testHttpConnection(): Unit = runBlocking {
6058
// S3
6159
assertConnect("https://aws-crt-test-stuff.s3.amazonaws.com")
6260
assertConnect("http://aws-crt-test-stuff.s3.amazonaws.com")
@@ -132,6 +130,7 @@ class HttpClientConnectionTest : CrtTest() {
132130
.forEach { pref ->
133131
TlsContext.build {
134132
tlsCipherPreference = pref
133+
println("connecting to $url with $pref")
135134
}.use { tlsContext ->
136135
val elapsed = measureTime {
137136
connect(url, clientBootstrap, tlsContext)

0 commit comments

Comments
 (0)