|
30 | 30 | import java.nio.file.Files; |
31 | 31 | import java.nio.file.Path; |
32 | 32 | import java.nio.file.StandardCopyOption; |
| 33 | +import java.security.MessageDigest; |
33 | 34 | import java.util.HashMap; |
34 | 35 | import java.util.List; |
35 | 36 | import java.util.Map; |
@@ -114,6 +115,38 @@ private Registry() { |
114 | 115 | this.registriesConf = RegistriesConf.newConf(); |
115 | 116 | } |
116 | 117 |
|
| 118 | + @Override |
| 119 | + public boolean canMount(OCI<?> other, ContainerRef sourceRef, ContainerRef targetRef) { |
| 120 | + if (!(other instanceof Registry otherRegistry)) { |
| 121 | + LOG.debug("Other OCI is not a registry, cannot mount"); |
| 122 | + return false; |
| 123 | + } |
| 124 | + // Not the same registry |
| 125 | + String effectiveSourceRegistry = sourceRef.getEffectiveRegistry(this); |
| 126 | + String effectiveTargetRegistry = targetRef.getEffectiveRegistry(otherRegistry); |
| 127 | + if (!effectiveSourceRegistry.equals(effectiveTargetRegistry)) { |
| 128 | + LOG.debug( |
| 129 | + "Cannot mount blob from registry {} to registry {}", |
| 130 | + effectiveSourceRegistry, |
| 131 | + effectiveTargetRegistry); |
| 132 | + return false; |
| 133 | + } |
| 134 | + // Not the same auth |
| 135 | + String authHeaderSource = authProvider.getAuthHeader(sourceRef); |
| 136 | + String authHeaderTarget = otherRegistry.authProvider.getAuthHeader(targetRef); |
| 137 | + if (!(authHeaderSource == authHeaderTarget |
| 138 | + || (authHeaderSource != null |
| 139 | + && authHeaderTarget != null |
| 140 | + && MessageDigest.isEqual( |
| 141 | + authHeaderSource.getBytes(StandardCharsets.UTF_8), |
| 142 | + authHeaderTarget.getBytes(StandardCharsets.UTF_8))))) { |
| 143 | + LOG.debug("Authentication is different between source and target registry, cannot mount"); |
| 144 | + return false; |
| 145 | + } |
| 146 | + LOG.debug("Blob can be mounted from registry {} to registry {}", sourceRef, targetRef); |
| 147 | + return true; |
| 148 | + } |
| 149 | + |
117 | 150 | /** |
118 | 151 | * Get the registries configuration |
119 | 152 | * @return The registries configuration |
|
0 commit comments