@@ -69,17 +69,29 @@ public final class ContainerRef extends Ref<ContainerRef> {
69
69
*/
70
70
private final @ Nullable String digest ;
71
71
72
+ /**
73
+ * Whether the container reference is unqualified without registry
74
+ */
75
+ private final boolean unqualified ;
76
+
72
77
/**
73
78
* Private constructor
74
79
* @param registry The registry where the container is stored.
80
+ * @param unqualified Whether the container reference is unqualified without registry
75
81
* @param namespace The namespace of the container.
76
82
* @param repository The repository where the container is stored
77
83
* @param tag The tag of the container.
78
84
* @param digest The digest of the container.
79
85
*/
80
86
private ContainerRef (
81
- String registry , @ Nullable String namespace , String repository , String tag , @ Nullable String digest ) {
87
+ String registry ,
88
+ boolean unqualified ,
89
+ @ Nullable String namespace ,
90
+ String repository ,
91
+ String tag ,
92
+ @ Nullable String digest ) {
82
93
super (tag );
94
+ this .unqualified = unqualified ;
83
95
this .registry = registry ;
84
96
this .namespace = namespace ;
85
97
this .repository = repository ;
@@ -94,6 +106,28 @@ public String getRegistry() {
94
106
return registry ;
95
107
}
96
108
109
+ /**
110
+ * Get the effective registry based on given target
111
+ * @param target The target registry
112
+ * @return The effective registry
113
+ */
114
+ public String getEffectiveRegistry (Registry target ) {
115
+ if (isUnqualified ()) {
116
+ if (target .getRegistry () != null ) {
117
+ return target .getRegistry ();
118
+ }
119
+ }
120
+ return registry ;
121
+ }
122
+
123
+ /**
124
+ * Whether the container reference is unqualified without registry
125
+ * @return True if unqualified
126
+ */
127
+ public boolean isUnqualified () {
128
+ return unqualified ;
129
+ }
130
+
97
131
/**
98
132
* Get the full repository name including the namespace if any
99
133
* @param registry The registry
@@ -181,7 +215,7 @@ public String getRepository() {
181
215
182
216
@ Override
183
217
public ContainerRef withDigest (String digest ) {
184
- return new ContainerRef (registry , namespace , repository , tag , digest );
218
+ return new ContainerRef (registry , unqualified , namespace , repository , tag , digest );
185
219
}
186
220
187
221
@ Override
@@ -329,11 +363,13 @@ public static ContainerRef parse(String name) {
329
363
String repository = matcher .group (3 );
330
364
String tag = matcher .group (4 );
331
365
String digest = matcher .group (5 );
366
+ boolean unqualified = false ;
332
367
if (repository == null ) {
333
368
throw new IllegalArgumentException ("You are minimally required to include a <namespace>/<repository>" );
334
369
}
335
370
if (registry == null ) {
336
371
registry = Const .DEFAULT_REGISTRY ;
372
+ unqualified = true ;
337
373
}
338
374
if (tag == null ) {
339
375
tag = Const .DEFAULT_TAG ;
@@ -348,7 +384,7 @@ public static ContainerRef parse(String name) {
348
384
SupportedAlgorithm .fromDigest (digest );
349
385
}
350
386
351
- return new ContainerRef (registry , namespace , repository , tag , digest );
387
+ return new ContainerRef (registry , unqualified , namespace , repository , tag , digest );
352
388
}
353
389
354
390
/**
@@ -357,7 +393,7 @@ public static ContainerRef parse(String name) {
357
393
* @return The container reference
358
394
*/
359
395
public ContainerRef forRegistry (String registry ) {
360
- return new ContainerRef (registry , namespace , repository , tag , digest );
396
+ return new ContainerRef (registry , false , namespace , repository , tag , digest );
361
397
}
362
398
363
399
/**
@@ -368,6 +404,7 @@ public ContainerRef forRegistry(String registry) {
368
404
public ContainerRef forRegistry (Registry registry ) {
369
405
return new ContainerRef (
370
406
registry .getRegistry () != null ? registry .getRegistry () : this .registry ,
407
+ false , // not unqualified if registry is set
371
408
namespace ,
372
409
repository ,
373
410
tag ,
0 commit comments