Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add oci registry plugin #2276

Draft
wants to merge 8 commits into
base: 4.x
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add blob finalizing
zrdzn committed Nov 22, 2024

Verified

This commit was signed with the committer’s verified signature.
zrdzn Kacper Żerdziński
commit 4144acce1ca231c4640a955882a2fa3351e3e00a
Original file line number Diff line number Diff line change
@@ -78,6 +78,20 @@ class OciFacade(
return session.asSuccess()
}

fun finalizeBlobUpload(namespace: String, digest: String, sessionId: String, lastPart: ByteArray?): Result<BlobResponse, ErrorResponse> {
val session = sessions[sessionId] ?: return notFoundError("Session not found")

if (lastPart != null) {
session.bytesReceived += lastPart.size
}

storageProvider.putFile("blobs/$namespace/$digest".toLocation(), session.uploadedData.inputStream())

sessions.remove(sessionId)

return findBlobByDigest(namespace, digest)
}

fun findBlobByDigest(namespace: String, digest: String): Result<BlobResponse, ErrorResponse> =
storageProvider.getFile("blobs/${namespace}/${digest}".toLocation())
.map {
Original file line number Diff line number Diff line change
@@ -90,6 +90,28 @@ internal class OciEndpoints(
}
}

fun finalizeBlobUpload(namespace: String) =
ReposiliteRoute<Unit>("/api/oci/v2/$namespace/blobs/{sessionId}", PUT) {
accessed {
val sessionId = parameter("sessionId") ?: return@accessed
val digest = queryParameter("digest")
if (digest == null) {
response = badRequestError("No digest provided")
return@accessed
}

response = supplyThrowing { ctx.bodyAsBytes() }
.fold(
{ ociFacade.finalizeBlobUpload(namespace, digest, sessionId, it) },
{ ociFacade.finalizeBlobUpload(namespace, digest, sessionId, null) },
)
.map {
ctx.status(201)
ctx.header("Location", "/api/oci/v2/$namespace/blobs/${it.digest}")
}
}
}

fun findBlobByDigest(namespace: String) =
ReposiliteRoute<ByteArray>("/api/oci/v2/$namespace/blobs/{digest}", GET, HEAD) {
accessed {
@@ -111,8 +133,10 @@ internal class OciEndpoints(
val reference = parameter("reference") ?: return@accessed

response = ociFacade.validateDigest(reference)
.flatMap { ociFacade.findManifestChecksumByDigest(namespace, reference) }
.flatMapErr { ociFacade.findManifestChecksumByTag(namespace, reference) }
.fold(
{ ociFacade.findManifestChecksumByDigest(namespace, reference) },
{ ociFacade.findManifestChecksumByTag(namespace, reference) }
)
.map {
ctx.status(200)
ctx.header("Docker-Content-Digest", it)