Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/docker-kotlin.api
Original file line number Diff line number Diff line change
Expand Up @@ -5135,6 +5135,11 @@ public final class me/devnatan/dockerkt/resource/image/ImageNotFoundException :
public final fun getImage ()Ljava/lang/String;
}

public final class me/devnatan/dockerkt/resource/image/ImagePullDeniedException : me/devnatan/dockerkt/resource/image/ImageException {
public final fun getImage ()Ljava/lang/String;
public fun getMessage ()Ljava/lang/String;
}

public final class me/devnatan/dockerkt/resource/image/ImageResource {
public static final field Companion Lme/devnatan/dockerkt/resource/image/ImageResource$Companion;
public final fun build (Ljava/lang/String;Lme/devnatan/dockerkt/models/image/ImageBuildOptions;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand Down
9 changes: 8 additions & 1 deletion api/docker-kotlin.klib.api
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Klib ABI Dump
// Targets: [linuxX64, macosX64, mingwX64]
// Targets: [linuxArm64, linuxX64, macosArm64, macosX64, mingwX64]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
Expand Down Expand Up @@ -5224,6 +5224,13 @@ final class me.devnatan.dockerkt.resource.image/ImageNotFoundException : me.devn
final fun <get-image>(): kotlin/String // me.devnatan.dockerkt.resource.image/ImageNotFoundException.image.<get-image>|<get-image>(){}[0]
}

final class me.devnatan.dockerkt.resource.image/ImagePullDeniedException : me.devnatan.dockerkt.resource.image/ImageException { // me.devnatan.dockerkt.resource.image/ImagePullDeniedException|null[0]
final val image // me.devnatan.dockerkt.resource.image/ImagePullDeniedException.image|{}image[0]
final fun <get-image>(): kotlin/String // me.devnatan.dockerkt.resource.image/ImagePullDeniedException.image.<get-image>|<get-image>(){}[0]
final val message // me.devnatan.dockerkt.resource.image/ImagePullDeniedException.message|{}message[0]
final fun <get-message>(): kotlin/String // me.devnatan.dockerkt.resource.image/ImagePullDeniedException.message.<get-message>|<get-message>(){}[0]
}

final class me.devnatan.dockerkt.resource.image/ImageResource { // me.devnatan.dockerkt.resource.image/ImageResource|null[0]
final fun pull(kotlin/String): kotlinx.coroutines.flow/Flow<me.devnatan.dockerkt.models.image/ImagePull> // me.devnatan.dockerkt.resource.image/ImageResource.pull|pull(kotlin.String){}[0]
final suspend fun build(kotlin/String, me.devnatan.dockerkt.models.image/ImageBuildOptions) // me.devnatan.dockerkt.resource.image/ImageResource.build|build(kotlin.String;me.devnatan.dockerkt.models.image.ImageBuildOptions){}[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ public class ImageNotFoundException internal constructor(
cause: Throwable?,
public val image: String,
) : ImageException(cause)

public class ImagePullDeniedException internal constructor(
cause: Throwable?,
public val image: String,
public override val message: String,
) : ImageException(cause)
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,27 @@ public class ImageResource internal constructor(

public fun pull(image: String): Flow<ImagePull> =
channelFlow {
httpClient
.preparePost("$BasePath/create") {
parameter("fromImage", image)
}.execute { response ->
val channel = response.body<ByteReadChannel>()
while (true) {
val line = channel.readUTF8Line() ?: break
send(json.decodeFromString(line))
requestCatching(
HttpStatusCode.NotFound to { exception ->
val errorMessage = exception.message.orEmpty().lowercase()
if (errorMessage.contains("no such image") || errorMessage.contains("manifest unknown")) {
ImageNotFoundException(exception, image)
} else {
ImagePullDeniedException(exception, image, exception.message.orEmpty())
}
}
},
) {
httpClient
.preparePost("$BasePath/create") {
parameter("fromImage", image)
}.execute { response ->
val channel = response.body<ByteReadChannel>()
while (true) {
val line = channel.readUTF8Line() ?: break
send(json.decodeFromString(line))
}
}
}
}

public suspend fun remove(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import kotlinx.coroutines.test.runTest
import me.devnatan.dockerkt.resource.ResourceIT
import me.devnatan.dockerkt.withImage
import kotlin.test.Test
import kotlin.test.assertFailsWith
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
import kotlin.test.fail
Expand All @@ -27,6 +28,27 @@ class ImageIT : ResourceIT() {
}
}

@Test
fun `image pull access denied image`() =
runTest {
assertFailsWith<ImagePullDeniedException> {
testClient.images.pull("inexistent:image").collect()
}
}

@Test
fun `image pull unknown image`() =
runTest {
try {
testClient.images.remove("busybox:billiejean", force = true)
} catch (_: ImageNotFoundException) {
}

assertFailsWith<ImageNotFoundException> {
testClient.images.pull("busybox:billiejean").collect()
}
}

@Test
fun `image remove`() =
runTest {
Expand Down
Loading