Skip to content

Commit fe3a10c

Browse files
committed
chore
1 parent 148b0d0 commit fe3a10c

File tree

10 files changed

+39
-29
lines changed

10 files changed

+39
-29
lines changed

api-client/src/main/kotlin/de/gesellix/docker/remote/api/client/ContainerApi.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ package de.gesellix.docker.remote.api.client
1515
import com.squareup.moshi.Json
1616
import com.squareup.moshi.Moshi
1717
import de.gesellix.docker.engine.DockerClientConfig
18-
import de.gesellix.docker.engine.RequestMethod.*
18+
import de.gesellix.docker.engine.RequestMethod.DELETE
19+
import de.gesellix.docker.engine.RequestMethod.GET
20+
import de.gesellix.docker.engine.RequestMethod.HEAD
21+
import de.gesellix.docker.engine.RequestMethod.POST
22+
import de.gesellix.docker.engine.RequestMethod.PUT
1923
import de.gesellix.docker.remote.api.ContainerCreateRequest
2024
import de.gesellix.docker.remote.api.ContainerCreateResponse
2125
import de.gesellix.docker.remote.api.ContainerInspectResponse
@@ -39,7 +43,6 @@ import de.gesellix.docker.remote.api.core.StreamCallback
3943
import de.gesellix.docker.remote.api.core.Success
4044
import de.gesellix.docker.remote.api.core.SuccessStream
4145
import kotlinx.coroutines.cancel
42-
import kotlinx.coroutines.flow.Flow
4346
import kotlinx.coroutines.launch
4447
import kotlinx.coroutines.runBlocking
4548
import kotlinx.coroutines.withTimeout
@@ -217,7 +220,7 @@ class ContainerApi(dockerClientConfig: DockerClientConfig = defaultClientConfig,
217220
launch {
218221
withTimeout(timeoutMillis) {
219222
callback.onStarting(this@launch::cancel)
220-
((localVarResponse as SuccessStream<*>).data as Flow<Frame>).collect { callback.onNext(it) }
223+
(localVarResponse as SuccessStream<Frame>).data.collect { callback.onNext(it) }
221224
callback.onFinished()
222225
}
223226
}
@@ -766,7 +769,7 @@ class ContainerApi(dockerClientConfig: DockerClientConfig = defaultClientConfig,
766769
)
767770

768771
return when (localVarResponse.responseType) {
769-
ResponseType.Success -> (localVarResponse as Success<*>).data as List<ContainerSummary>
772+
ResponseType.Success -> (localVarResponse as Success<List<ContainerSummary>>).data
770773
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
771774
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
772775
ResponseType.ClientError -> {
@@ -859,7 +862,7 @@ class ContainerApi(dockerClientConfig: DockerClientConfig = defaultClientConfig,
859862
launch {
860863
withTimeout(timeoutMillis) {
861864
callback.onStarting(this@launch::cancel)
862-
((localVarResponse as SuccessStream<*>).data as Flow<Frame>).collect { callback.onNext(it) }
865+
(localVarResponse as SuccessStream<Frame>).data.collect { callback.onNext(it) }
863866
callback.onFinished()
864867
}
865868
}

api-client/src/main/kotlin/de/gesellix/docker/remote/api/client/ExecApi.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ import de.gesellix.docker.remote.api.core.StreamCallback
3333
import de.gesellix.docker.remote.api.core.Success
3434
import de.gesellix.docker.remote.api.core.SuccessStream
3535
import kotlinx.coroutines.cancel
36-
import kotlinx.coroutines.flow.Flow
37-
import kotlinx.coroutines.flow.collect
3836
import kotlinx.coroutines.launch
3937
import kotlinx.coroutines.runBlocking
4038
import kotlinx.coroutines.withTimeoutOrNull
@@ -263,7 +261,7 @@ class ExecApi(dockerClientConfig: DockerClientConfig = defaultClientConfig, prox
263261
launch {
264262
withTimeoutOrNull(timeout.toMillis()) {
265263
actualCallback.onStarting(this@launch::cancel)
266-
((localVarResponse as SuccessStream<*>).data as Flow<Frame>).collect { actualCallback.onNext(it) }
264+
(localVarResponse as SuccessStream<Frame>).data.collect { actualCallback.onNext(it) }
267265
actualCallback.onFinished()
268266
}
269267
}

api-client/src/main/kotlin/de/gesellix/docker/remote/api/client/ServiceApi.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import de.gesellix.docker.remote.api.core.StreamCallback
3535
import de.gesellix.docker.remote.api.core.Success
3636
import de.gesellix.docker.remote.api.core.SuccessStream
3737
import kotlinx.coroutines.cancel
38-
import kotlinx.coroutines.flow.Flow
3938
import kotlinx.coroutines.launch
4039
import kotlinx.coroutines.runBlocking
4140
import kotlinx.coroutines.withTimeout
@@ -241,7 +240,7 @@ class ServiceApi(dockerClientConfig: DockerClientConfig = defaultClientConfig, p
241240
)
242241

243242
return when (localVarResponse.responseType) {
244-
ResponseType.Success -> (localVarResponse as Success<*>).data as List<Service>
243+
ResponseType.Success -> (localVarResponse as Success<List<Service>>).data
245244
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
246245
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
247246
ResponseType.ClientError -> {
@@ -325,7 +324,7 @@ class ServiceApi(dockerClientConfig: DockerClientConfig = defaultClientConfig, p
325324
launch {
326325
withTimeout(timeoutMillis) {
327326
callback.onStarting(this@launch::cancel)
328-
((localVarResponse as SuccessStream<*>).data as Flow<Frame>).collect { callback.onNext(it) }
327+
(localVarResponse as SuccessStream<Frame>).data.collect { callback.onNext(it) }
329328
callback.onFinished()
330329
}
331330
}

api-client/src/main/kotlin/de/gesellix/docker/remote/api/client/TaskApi.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import de.gesellix.docker.remote.api.core.StreamCallback
2828
import de.gesellix.docker.remote.api.core.Success
2929
import de.gesellix.docker.remote.api.core.SuccessStream
3030
import kotlinx.coroutines.cancel
31-
import kotlinx.coroutines.flow.Flow
3231
import kotlinx.coroutines.launch
3332
import kotlinx.coroutines.runBlocking
3433
import kotlinx.coroutines.withTimeout
@@ -115,7 +114,7 @@ class TaskApi(dockerClientConfig: DockerClientConfig = defaultClientConfig, prox
115114
)
116115

117116
return when (localVarResponse.responseType) {
118-
ResponseType.Success -> (localVarResponse as Success<*>).data as List<Task>
117+
ResponseType.Success -> (localVarResponse as Success<List<Task>>).data
119118
ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.")
120119
ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.")
121120
ResponseType.ClientError -> {
@@ -195,7 +194,7 @@ class TaskApi(dockerClientConfig: DockerClientConfig = defaultClientConfig, prox
195194
launch {
196195
withTimeout(timeoutMillis) {
197196
callback.onStarting(this@launch::cancel)
198-
((localVarResponse as SuccessStream<*>).data as Flow<Frame>).collect { callback.onNext(it) }
197+
(localVarResponse as SuccessStream<Frame>).data.collect { callback.onNext(it) }
199198
callback.onFinished()
200199
}
201200
}

api-client/src/main/kotlin/de/gesellix/docker/remote/api/core/ApiClient.kt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ open class ApiClient(
4444
protected const val TextPlainMediaType = "text/plain"
4545
protected const val JsonMediaType = "application/json"
4646
protected const val OctetStreamMediaType = "application/octet-stream"
47-
protected const val DockerRawStreamMediaType = "application/vnd.docker.raw-stream"
47+
// see https://docs.docker.com/engine/api/version-history/#v142-api-changes
48+
// see https://github.com/moby/moby/pull/39812
49+
// raw-stream: with attached Tty
50+
const val DockerRawStreamMediaType = "application/vnd.docker.raw-stream"
51+
// see https://docs.docker.com/engine/api/version-history/#v142-api-changes
52+
// see https://github.com/moby/moby/pull/39812
53+
// multiplexed-stream: without attached Tty
54+
const val DockerMultiplexedStreamMediaType = "application/vnd.docker.multiplexed-stream"
4855

4956
// val apiKey: MutableMap<String, String> = mutableMapOf()
5057
// val apiKeyPrefix: MutableMap<String, String> = mutableMapOf()
@@ -254,13 +261,13 @@ open class ApiClient(
254261
)
255262
response.isClientError -> return ClientError(
256263
response.message,
257-
response.body?.string(),
264+
response.body.string(),
258265
response.code,
259266
response.headers.toMultimap()
260267
)
261268
else -> return ServerError(
262269
response.message,
263-
response.body?.string(),
270+
response.body.string(),
264271
response.code,
265272
response.headers.toMultimap()
266273
)
@@ -289,13 +296,13 @@ open class ApiClient(
289296
)
290297
response.isClientError -> return ClientError(
291298
response.message,
292-
response.body?.string(),
299+
response.body.string(),
293300
response.code,
294301
response.headers.toMultimap()
295302
)
296303
else -> return ServerError(
297304
response.message,
298-
response.body?.string(),
305+
response.body.string(),
299306
response.code,
300307
response.headers.toMultimap()
301308
)
@@ -324,13 +331,13 @@ open class ApiClient(
324331
)
325332
response.isClientError -> return ClientError(
326333
response.message,
327-
response.body?.string(),
334+
response.body.string(),
328335
response.code,
329336
response.headers.toMultimap()
330337
)
331338
else -> return ServerError(
332339
response.message,
333-
response.body?.string(),
340+
response.body.string(),
334341
response.code,
335342
response.headers.toMultimap()
336343
)

api-client/src/main/kotlin/de/gesellix/docker/remote/api/core/EnforceResponseContentTypeInterceptor.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import java.net.HttpURLConnection.HTTP_NO_CONTENT
77
data class EnforceResponseContentTypeConfig(val fallbackContentType: String = "")
88

99
// This one would work automatically, when the response content-type would be set correctly :-/
10-
// - for /attach, /logs and similar endpoints see https://github.com/gesellix/docker-client/issues/21
10+
// see https://github.com/gesellix/docker-client/issues/21
11+
// see https://github.com/moby/moby/pull/39812
12+
// - for /attach, /logs and similar endpoints the issue has been fixed with api version 1.42
1113
// - for /stats see (?)
1214
class EnforceResponseContentTypeInterceptor : Interceptor {
1315

api-client/src/main/kotlin/de/gesellix/docker/remote/api/core/ResponseConsumer.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ fun ResponseBody?.consumeFrames(mediaType: String?, expectMultiplexedResponse: B
6262
return emptyFlow()
6363
}
6464
when (mediaType) {
65-
// TODO since api v1.42 we should be able to use the media-type instead of the 'expectMultiplexedResponse' flag
66-
// see https://docs.docker.com/engine/api/version-history/#v142-api-changes
67-
"application/vnd.docker.multiplexed-stream",
68-
"application/vnd.docker.raw-stream" -> {
65+
// multiplexed-stream: without attached Tty
66+
ApiClient.Companion.DockerMultiplexedStreamMediaType,
67+
// raw-stream: with attached Tty
68+
ApiClient.Companion.DockerRawStreamMediaType -> {
6969
val reader = FrameReader(source(), expectMultiplexedResponse)
7070
val events = flow {
7171
while (reader.hasNext()) {

api-client/src/test/java/de/gesellix/docker/remote/api/client/ContainerApiIntegrationTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,9 @@ public void containerAttachNonInteractive() {
795795
new Timer().schedule(new TimerTask() {
796796
@Override
797797
public void run() {
798-
callback.job.cancel();
798+
if (callback.job != null) {
799+
callback.job.cancel();
800+
}
799801
wait.countDown();
800802
}
801803
}, 5000);

api-client/src/test/java/de/gesellix/docker/remote/api/client/SystemApiIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public void systemPingHead() {
141141
@Test
142142
public void systemVersion() {
143143
SystemVersion systemVersion = systemApi.systemVersion();
144-
assertTrue(asList("1.42", "1.43", "1.44", "1.45", "1.46", "1.47", "1.48").contains(systemVersion.getApiVersion()));
144+
assertTrue(asList("1.42", "1.43", "1.44", "1.45", "1.46", "1.47", "1.48", "1.49", "1.50", "1.51").contains(systemVersion.getApiVersion()));
145145
}
146146

147147
static class SystemEventsCallback implements StreamCallback<EventMessage> {

api-client/src/test/java/de/gesellix/docker/remote/api/testutil/TestImage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public TestImage(EngineApiClient engineApiClient) {
1616

1717
this.useWindowsContainer = Objects.requireNonNull(engineApiClient.getSystemApi().systemVersion().getOs()).equalsIgnoreCase("windows");
1818
this.repository = "gesellix/echo-server";
19-
this.tag = "2024-12-22T16-35-00";
19+
this.tag = "2025-07-27T22-12-00";
2020

2121
// TODO consider NOT calling prepare inside the constructor
2222
prepare();

0 commit comments

Comments
 (0)