From 17496e936e2bc6df8a428c04e882fad6b19f5085 Mon Sep 17 00:00:00 2001 From: Silvio Giebl Date: Tue, 16 Jul 2024 17:56:32 +0200 Subject: [PATCH] Rename registry -> registryUrl in OciRegistryApi --- .../oci/internal/registry/OciRegistryApi.kt | 118 +++++++++--------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/registry/OciRegistryApi.kt b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/registry/OciRegistryApi.kt index 5a60559f..7977a08a 100644 --- a/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/registry/OciRegistryApi.kt +++ b/src/main/kotlin/io/github/sgtsilvio/gradle/oci/internal/registry/OciRegistryApi.kt @@ -74,7 +74,7 @@ internal class OciRegistryApi(httpClient: HttpClient) { Caffeine.newBuilder().expireAfter(TokenCacheExpiry).buildAsync() private data class TokenCacheKey( - val registry: URI, + val registryUrl: URI, val scopes: Set, val credentials: HashedCredentials?, ) @@ -99,13 +99,13 @@ internal class OciRegistryApi(httpClient: HttpClient) { } private fun pullManifestInternal( - registry: URI, + registryUrl: URI, imageName: String, reference: String, credentials: Credentials?, ): Mono { return send( - registry, + registryUrl, imageName, "manifests/$reference", setOf(OciRegistryResourceScope(RESOURCE_SCOPE_REPOSITORY_TYPE, imageName, RESOURCE_SCOPE_PULL_ACTIONS)), @@ -133,22 +133,22 @@ internal class OciRegistryApi(httpClient: HttpClient) { } fun pullManifest( - registry: URI, + registryUrl: URI, imageName: String, reference: String, credentials: Credentials?, ): Mono = when { - ':' in reference -> pullManifest(registry, imageName, reference.toOciDigest(), -1, credentials) - else -> pullManifestInternal(registry, imageName, reference, credentials) + ':' in reference -> pullManifest(registryUrl, imageName, reference.toOciDigest(), -1, credentials) + else -> pullManifestInternal(registryUrl, imageName, reference, credentials) } fun pullManifest( - registry: URI, + registryUrl: URI, imageName: String, digest: OciDigest, size: Int, credentials: Credentials?, - ): Mono = pullManifestInternal(registry, imageName, digest.toString(), credentials).map { manifest -> + ): Mono = pullManifestInternal(registryUrl, imageName, digest.toString(), credentials).map { manifest -> val manifestBytes = manifest.bytes if ((size != -1) && (size != manifestBytes.size)) { throw sizeMismatchException(size.toLong(), manifestBytes.size.toLong()) @@ -163,7 +163,7 @@ internal class OciRegistryApi(httpClient: HttpClient) { } fun pullBlob( - registry: URI, + registryUrl: URI, imageName: String, digest: OciDigest, size: Long, @@ -171,7 +171,7 @@ internal class OciRegistryApi(httpClient: HttpClient) { bodyMapper: ByteBufFlux.() -> Publisher, ): Flux { return send( - registry, + registryUrl, imageName, "blobs/$digest", setOf(OciRegistryResourceScope(RESOURCE_SCOPE_REPOSITORY_TYPE, imageName, RESOURCE_SCOPE_PULL_ACTIONS)), @@ -188,14 +188,14 @@ internal class OciRegistryApi(httpClient: HttpClient) { } fun pullBlobAsString( - registry: URI, + registryUrl: URI, imageName: String, digest: OciDigest, size: Long, credentials: Credentials?, ): Mono { return pullBlob( - registry, + registryUrl, imageName, digest, size, @@ -206,13 +206,13 @@ internal class OciRegistryApi(httpClient: HttpClient) { // data class ManifestMetadata(val present: Boolean, val mediaType: String?, val digest: OciDigest?, val size: Int) // // fun isManifestPresent( -// registry: URI, +// registryUrl: URI, // imageName: String, // reference: String, // credentials: Credentials?, // ): Mono { // return send( -// registry, +// registryUrl, // imageName, // "manifests/$reference", // setOf(OciRegistryResourceScope(RESOURCE_SCOPE_REPOSITORY_TYPE, imageName, RESOURCE_SCOPE_PULL_ACTIONS)), @@ -244,20 +244,20 @@ internal class OciRegistryApi(httpClient: HttpClient) { // } // // fun isManifestPresent( -// registry: URI, +// registryUrl: URI, // imageName: String, // digest: OciDigest, // credentials: Credentials?, -// ): Mono = isManifestPresent(registry, imageName, digest.toString(), credentials) +// ): Mono = isManifestPresent(registryUrl, imageName, digest.toString(), credentials) fun isBlobPresent( - registry: URI, + registryUrl: URI, imageName: String, digest: OciDigest, credentials: Credentials?, ): Mono { return send( - registry, + registryUrl, imageName, "blobs/$digest", setOf(OciRegistryResourceScope(RESOURCE_SCOPE_REPOSITORY_TYPE, imageName, RESOURCE_SCOPE_PULL_ACTIONS)), @@ -273,7 +273,7 @@ internal class OciRegistryApi(httpClient: HttpClient) { } fun mountBlobOrCreatePushUrl( - registry: URI, + registryUrl: URI, imageName: String, digest: OciDigest?, sourceImageName: String?, @@ -292,7 +292,7 @@ internal class OciRegistryApi(httpClient: HttpClient) { } } val mono = send( - registry, + registryUrl, imageName, "blobs/uploads/$query", scopes, @@ -302,7 +302,7 @@ internal class OciRegistryApi(httpClient: HttpClient) { when (response.status().code()) { 201 -> if (isMount) body.then(Mono.empty()) else createError(response, body.aggregate()) 202 -> response.responseHeaders()[HttpHeaderNames.LOCATION]?.let { location -> - body.then(registry.resolve(location).toMono()) + body.then(registryUrl.resolve(location).toMono()) } ?: createError(response, body.aggregate()) else -> createError(response, body.aggregate()) @@ -311,20 +311,20 @@ internal class OciRegistryApi(httpClient: HttpClient) { return if (isMount && (sourceImageName != null)) { mono.onErrorResume { error -> if (error is InsufficientScopesException) { - mountBlobOrCreatePushUrl(registry, imageName, null, null, credentials) + mountBlobOrCreatePushUrl(registryUrl, imageName, null, null, credentials) } else throw error } } else mono } // fun cancelBlobPush( -// registry: URI, +// registryUrl: URI, // imageName: String, // credentials: Credentials?, // uri: URI, // ): Mono { // return send( -// registry, +// registryUrl, // setOf(OciRegistryResourceScope(RESOURCE_SCOPE_REPOSITORY_TYPE, imageName, RESOURCE_SCOPE_DELETE_ACTIONS)), // credentials, // { delete().uri(uri) }, @@ -337,7 +337,7 @@ internal class OciRegistryApi(httpClient: HttpClient) { // } fun pushBlob( - registry: URI, + registryUrl: URI, imageName: String, digest: OciDigest, size: Long, @@ -346,7 +346,7 @@ internal class OciRegistryApi(httpClient: HttpClient) { sender: NettyOutbound.() -> Publisher, ): Mono { return send( - registry, + registryUrl, setOf(OciRegistryResourceScope(RESOURCE_SCOPE_REPOSITORY_TYPE, imageName, RESOURCE_SCOPE_PUSH_ACTIONS)), credentials, { @@ -364,7 +364,7 @@ internal class OciRegistryApi(httpClient: HttpClient) { } fun mountOrPushBlob( - registry: URI, + registryUrl: URI, imageName: String, digest: OciDigest, size: Long, @@ -372,12 +372,12 @@ internal class OciRegistryApi(httpClient: HttpClient) { credentials: Credentials?, sender: NettyOutbound.() -> Publisher, ): Mono = - mountBlobOrCreatePushUrl(registry, imageName, digest, sourceImageName, credentials).flatMap { uri -> - pushBlob(registry, imageName, digest, size, uri, credentials, sender) + mountBlobOrCreatePushUrl(registryUrl, imageName, digest, sourceImageName, credentials).flatMap { uri -> + pushBlob(registryUrl, imageName, digest, size, uri, credentials, sender) } fun pushBlobIfNotPresent( - registry: URI, + registryUrl: URI, imageName: String, digest: OciDigest, size: Long, @@ -386,15 +386,15 @@ internal class OciRegistryApi(httpClient: HttpClient) { sender: NettyOutbound.() -> Publisher, ): Mono { return if ((sourceImageName == null) || (sourceImageName == imageName)) { - mountOrPushBlob(registry, imageName, digest, size, imageName, credentials, sender) - } else isBlobPresent(registry, imageName, digest, credentials).flatMap { present -> + mountOrPushBlob(registryUrl, imageName, digest, size, imageName, credentials, sender) + } else isBlobPresent(registryUrl, imageName, digest, credentials).flatMap { present -> if (present) Mono.empty() - else mountOrPushBlob(registry, imageName, digest, size, sourceImageName, credentials, sender) + else mountOrPushBlob(registryUrl, imageName, digest, size, sourceImageName, credentials, sender) } } fun pushManifest( - registry: URI, + registryUrl: URI, imageName: String, reference: String, mediaType: String, @@ -402,7 +402,7 @@ internal class OciRegistryApi(httpClient: HttpClient) { credentials: Credentials?, ): Mono { return send( - registry, + registryUrl, imageName, "manifests/$reference", setOf(OciRegistryResourceScope(RESOURCE_SCOPE_REPOSITORY_TYPE, imageName, RESOURCE_SCOPE_PUSH_ACTIONS)), @@ -422,46 +422,46 @@ internal class OciRegistryApi(httpClient: HttpClient) { } // fun pushManifest( -// registry: URI, +// registryUrl: URI, // imageName: String, // digest: OciDigest, // mediaType: String, // data: ByteArray, // credentials: Credentials?, -// ): Mono = pushManifest(registry, imageName, digest.toString(), mediaType, data, credentials) +// ): Mono = pushManifest(registryUrl, imageName, digest.toString(), mediaType, data, credentials) // // fun pushManifestIfNotPresent( -// registry: URI, +// registryUrl: URI, // imageName: String, // reference: String, // mediaType: String, // data: ByteArray, // credentials: Credentials?, -// ): Mono = isManifestPresent(registry, imageName, reference, credentials).flatMap { (present) -> +// ): Mono = isManifestPresent(registryUrl, imageName, reference, credentials).flatMap { (present) -> // if (present) Mono.empty() -// else pushManifest(registry, imageName, reference, mediaType, data, credentials) +// else pushManifest(registryUrl, imageName, reference, mediaType, data, credentials) // } // // fun pushManifestIfNotPresent( -// registry: URI, +// registryUrl: URI, // imageName: String, // digest: OciDigest, // mediaType: String, // data: ByteArray, // credentials: Credentials?, -// ): Mono = isManifestPresent(registry, imageName, digest, credentials).flatMap { (present) -> +// ): Mono = isManifestPresent(registryUrl, imageName, digest, credentials).flatMap { (present) -> // if (present) Mono.empty() -// else pushManifest(registry, imageName, digest, mediaType, data, credentials) +// else pushManifest(registryUrl, imageName, digest, mediaType, data, credentials) // } // // fun deleteBlob( -// registry: URI, +// registryUrl: URI, // imageName: String, // digest: OciDigest, // credentials: Credentials?, // ): Mono { // return send( -// registry, +// registryUrl, // imageName, // "blobs/$digest", // setOf(OciRegistryResourceScope(RESOURCE_SCOPE_REPOSITORY_TYPE, imageName, RESOURCE_SCOPE_DELETE_ACTIONS)), @@ -476,13 +476,13 @@ internal class OciRegistryApi(httpClient: HttpClient) { // } // // fun deleteManifest( -// registry: URI, +// registryUrl: URI, // imageName: String, // reference: String, // credentials: Credentials?, // ): Mono { // return send( -// registry, +// registryUrl, // imageName, // "manifests/$reference", // setOf(OciRegistryResourceScope(RESOURCE_SCOPE_REPOSITORY_TYPE, imageName, RESOURCE_SCOPE_DELETE_ACTIONS)), @@ -497,14 +497,14 @@ internal class OciRegistryApi(httpClient: HttpClient) { // } // // fun deleteManifest( -// registry: URI, +// registryUrl: URI, // imageName: String, // digest: OciDigest, // credentials: Credentials?, -// ): Mono = deleteManifest(registry, imageName, digest.toString(), credentials) +// ): Mono = deleteManifest(registryUrl, imageName, digest.toString(), credentials) private fun send( - registry: URI, + registryUrl: URI, imageName: String, path: String, scopes: Set, @@ -512,29 +512,29 @@ internal class OciRegistryApi(httpClient: HttpClient) { requestAction: HttpClient.() -> HttpClient.ResponseReceiver<*>, responseAction: (HttpClientResponse, ByteBufFlux) -> Publisher, ) = send( - registry, + registryUrl, scopes, credentials, - { requestAction().uri("$registry/v2/$imageName/$path") }, + { requestAction().uri("$registryUrl/v2/$imageName/$path") }, responseAction, ) private fun send( - registry: URI, + registryUrl: URI, scopes: Set, credentials: Credentials?, requestAction: HttpClient.() -> HttpClient.ResponseReceiver<*>, responseAction: (HttpClientResponse, ByteBufFlux) -> Publisher, ): Flux { return httpClient.headersWhen { headers -> - getAuthorization(registry, scopes, credentials).map { authorization -> + getAuthorization(registryUrl, scopes, credentials).map { authorization -> headers.set(HttpHeaderNames.AUTHORIZATION, authorization) }.defaultIfEmpty(headers) }.requestAction().response(responseAction).retryWhen(RETRY_SPEC).onErrorResume { error -> when { error !is HttpResponseException -> throw error error.statusCode != 401 -> throw error - else -> tryAuthorize(error.headers, registry, scopes, credentials)?.flatMapMany { authorization -> + else -> tryAuthorize(error.headers, registryUrl, scopes, credentials)?.flatMapMany { authorization -> httpClient.headers { headers -> headers[HttpHeaderNames.AUTHORIZATION] = authorization }.requestAction().response(responseAction).retryWhen(RETRY_SPEC) @@ -545,7 +545,7 @@ internal class OciRegistryApi(httpClient: HttpClient) { private fun tryAuthorize( responseHeaders: HttpHeaders, - registry: URI, + registryUrl: URI, scopes: Set, credentials: Credentials?, ): Mono? { @@ -557,7 +557,7 @@ internal class OciRegistryApi(httpClient: HttpClient) { if (scopesFromResponse != scopes) { throw IllegalStateException("scopes do not match, required: $scopes, from bearer authorization header: $scopesFromResponse") } - return tokenCache.getMono(TokenCacheKey(registry, scopes, credentials?.hashed())) { key -> + return tokenCache.getMono(TokenCacheKey(registryUrl, scopes, credentials?.hashed())) { key -> val scopeParams = key.scopes.joinToString("&scope=", "scope=") { it.encodeToString() } httpClient.headers { headers -> if (credentials != null) { @@ -588,11 +588,11 @@ internal class OciRegistryApi(httpClient: HttpClient) { } private fun getAuthorization( - registry: URI, + registryUrl: URI, scopes: Set, credentials: Credentials?, ): Mono { - return tokenCache.getIfPresentMono(TokenCacheKey(registry, scopes, credentials?.hashed())) + return tokenCache.getIfPresentMono(TokenCacheKey(registryUrl, scopes, credentials?.hashed())) .map { encodeBearerAuthorization(it.jws) } .run { if (credentials == null) this else defaultIfEmpty(credentials.encodeBasicAuthorization()) } }