@@ -41,6 +41,7 @@ import retrofit2.http.Header
41
41
import retrofit2.http.Headers
42
42
import retrofit2.http.Path
43
43
import retrofit2.http.Query
44
+ import retrofit2.http.QueryMap
44
45
45
46
import java.time.Instant
46
47
@@ -242,7 +243,8 @@ class DockerRegistryClient {
242
243
@Headers ([
243
244
" Docker-Distribution-API-Version: registry/2.0"
244
245
])
245
- Call<ResponseBody > getTags (@Path (value = " repository" , encoded = true ) String repository , @Header (" Authorization" ) String token , @Header (" User-Agent" ) String agent )
246
+ Call<ResponseBody > getTags (@Path (value = " repository" , encoded = true ) String repository , @Header (" Authorization" ) String token , @Header (" User-Agent" ) String agent , @QueryMap Map<String , String > queryParams )
247
+
246
248
247
249
@GET (" /v2/{name}/manifests/{reference}" )
248
250
@Headers ([
@@ -261,13 +263,15 @@ class DockerRegistryClient {
261
263
@Headers ([
262
264
" Docker-Distribution-API-Version: registry/2.0"
263
265
])
264
- Call<ResponseBody > getCatalog (@Query (value = " n" ) int paginateSize , @Header (" Authorization" ) String token , @Header (" User-Agent" ) String agent )
266
+ Call<ResponseBody > getCatalog (@Header (" Authorization" ) String token , @Header (" User-Agent" ) String agent , @QueryMap Map<String , String > queryParams )
267
+
265
268
266
269
@GET (" /{path}" )
267
270
@Headers ([
268
271
" Docker-Distribution-API-Version: registry/2.0"
269
272
])
270
- Call<ResponseBody > get (@Path (value = " path" , encoded = true ) String path , @Header (" Authorization" ) String token , @Header (" User-Agent" ) String agent )
273
+ Call<ResponseBody > get (@Path (value = " path" , encoded = true ) String path , @Header (" Authorization" ) String token , @Header (" User-Agent" ) String agent , @QueryMap Map<String , String > queryParams )
274
+
271
275
272
276
@GET (" /v2/" )
273
277
@Headers ([
@@ -406,7 +410,7 @@ class DockerRegistryClient {
406
410
* This method will get all repositories available on this registry. It may fail, as some registries
407
411
* don't want you to download their whole catalog (it's potentially a lot of data).
408
412
*/
409
- public DockerRegistryCatalog getCatalog (String path = null ) {
413
+ public DockerRegistryCatalog getCatalog (String path = null , Map< String , String > queryParams = [:] ) {
410
414
if (catalogFile) {
411
415
log. info(" Using catalog list at $catalogFile " )
412
416
try {
@@ -417,14 +421,15 @@ class DockerRegistryClient {
417
421
}
418
422
}
419
423
424
+ queryParams. computeIfAbsent(" n" , { paginateSize. toString() })
420
425
def response
421
426
try {
422
427
response = request({
423
- path ? Retrofit2SyncCall . executeCall(registryService. get(path, tokenService. basicAuthHeader, userAgent)) :
424
- Retrofit2SyncCall . executeCall(registryService. getCatalog(paginateSize, tokenService. basicAuthHeader, userAgent))
428
+ path ? Retrofit2SyncCall . executeCall(registryService. get(path, tokenService. basicAuthHeader, userAgent, queryParams )) :
429
+ Retrofit2SyncCall . executeCall(registryService. getCatalog(tokenService. basicAuthHeader, userAgent, queryParams ))
425
430
}, { token ->
426
- path ? Retrofit2SyncCall . executeCall(registryService. get(path, token, userAgent)) :
427
- Retrofit2SyncCall . executeCall(registryService. getCatalog(paginateSize, token, userAgent))
431
+ path ? Retrofit2SyncCall . executeCall(registryService. get(path, token, userAgent, queryParams )) :
432
+ Retrofit2SyncCall . executeCall(registryService. getCatalog(token, userAgent, queryParams ))
428
433
}, " _catalog" )
429
434
} catch (Exception e) {
430
435
log. warn(" Error encountered during catalog of $path " , e)
@@ -438,33 +443,55 @@ class DockerRegistryClient {
438
443
catalog. repositories = catalog. repositories. findAll { it ==~ repositoriesRegex }
439
444
}
440
445
if (nextPath) {
441
- def nextCatalog = getCatalog(nextPath)
446
+ def nextPathNew
447
+ (nextPathNew, queryParams) = parseForQueryParams(nextPath)
448
+ def nextCatalog = getCatalog(nextPathNew, queryParams)
442
449
catalog. repositories. addAll(nextCatalog. repositories)
443
450
}
444
451
445
452
return catalog
446
453
}
447
454
448
- public DockerRegistryTags getTags (String repository , String path = null ) {
455
+ public DockerRegistryTags getTags (String repository , String path = null , Map< String , String > queryParams = [:] ) {
449
456
def response = request({
450
- path ? Retrofit2SyncCall . executeCall(registryService. get(path, tokenService. basicAuthHeader, userAgent)) :
451
- Retrofit2SyncCall . executeCall(registryService. getTags(repository, tokenService. basicAuthHeader, userAgent))
457
+ path ? Retrofit2SyncCall . executeCall(registryService. get(path, tokenService. basicAuthHeader, userAgent, queryParams )) :
458
+ Retrofit2SyncCall . executeCall(registryService. getTags(repository, tokenService. basicAuthHeader, userAgent, queryParams ))
452
459
}, { token ->
453
- path ? Retrofit2SyncCall . executeCall(registryService. get(path, token, userAgent)) :
454
- Retrofit2SyncCall . executeCall(registryService. getTags(repository, token, userAgent))
460
+ path ? Retrofit2SyncCall . executeCall(registryService. get(path, token, userAgent, queryParams )) :
461
+ Retrofit2SyncCall . executeCall(registryService. getTags(repository, token, userAgent, queryParams ))
455
462
}, repository)
456
463
457
464
def nextPath = findNextLink(response?. headers())
458
465
def tags = convertResponseBody(response. body(), DockerRegistryTags )
459
466
460
467
if (nextPath) {
461
- def nextTags = getTags(repository, nextPath)
468
+ def nextPathNew
469
+ (nextPathNew, queryParams) = parseForQueryParams(nextPath)
470
+ def nextTags = getTags(repository, nextPathNew, queryParams)
462
471
tags. tags. addAll(nextTags. tags)
463
472
}
464
473
465
474
return tags
466
475
}
467
476
477
+ static def parseForQueryParams (String nextPath ) {
478
+ def nextPathNew
479
+ def queryParamsString
480
+ Map<String , String > queryParams = [:]
481
+ if (nextPath. contains(" ?" )) {
482
+ (nextPathNew, queryParamsString) = nextPath. split(" \\ ?" , 2 )
483
+ } else {
484
+ nextPathNew = nextPath
485
+ }
486
+ if (queryParamsString) {
487
+ queryParams = queryParamsString. split(" &" ). collectEntries { param ->
488
+ def (key, value) = param. split(" =" )
489
+ [key, value]
490
+ }
491
+ }
492
+ [nextPathNew, queryParams]
493
+ }
494
+
468
495
/*
469
496
* This method will hit the /v2/ endpoint of the configured docker registry. If it this endpoint is up,
470
497
* it will return silently. Otherwise, an exception is thrown detailing why the endpoint isn't available.
0 commit comments