Allow direct download templates from IPv6 host address. (#5900)

* Allow templates & ISOs from IPv6 host address.

* fix checkstyle issue

* Allow only direct download templates from IPv6 address

Co-authored-by: gabriel <gabriel@apache.org>
This commit is contained in:
sureshanaparti 2022-01-28 09:50:32 +05:30 committed by GitHub
parent 6fa8538666
commit 0e150954d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -216,7 +216,7 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase {
public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocationException { public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocationException {
TemplateProfile profile = super.prepare(cmd); TemplateProfile profile = super.prepare(cmd);
String url = profile.getUrl(); String url = profile.getUrl();
UriUtils.validateUrl(cmd.getFormat(), url); UriUtils.validateUrl(cmd.getFormat(), url, cmd.isDirectDownload());
if (cmd.isDirectDownload()) { if (cmd.isDirectDownload()) {
DigestHelper.validateChecksumString(cmd.getChecksum()); DigestHelper.validateChecksumString(cmd.getChecksum());
Long templateSize = performDirectDownloadUrlValidation(cmd.getFormat(), url, cmd.getZoneIds()); Long templateSize = performDirectDownloadUrlValidation(cmd.getFormat(), url, cmd.getZoneIds());

View File

@ -263,6 +263,10 @@ public class UriUtils {
} }
public static Pair<String, Integer> validateUrl(String format, String url) throws IllegalArgumentException { public static Pair<String, Integer> validateUrl(String format, String url) throws IllegalArgumentException {
return validateUrl(format, url, false);
}
public static Pair<String, Integer> validateUrl(String format, String url, boolean skipIpv6Check) throws IllegalArgumentException {
try { try {
URI uri = new URI(url); URI uri = new URI(url);
if ((uri.getScheme() == null) || if ((uri.getScheme() == null) ||
@ -283,7 +287,7 @@ public class UriUtils {
if (hostAddr.isAnyLocalAddress() || hostAddr.isLinkLocalAddress() || hostAddr.isLoopbackAddress() || hostAddr.isMulticastAddress()) { if (hostAddr.isAnyLocalAddress() || hostAddr.isLinkLocalAddress() || hostAddr.isLoopbackAddress() || hostAddr.isMulticastAddress()) {
throw new IllegalArgumentException("Illegal host specified in url"); throw new IllegalArgumentException("Illegal host specified in url");
} }
if (hostAddr instanceof Inet6Address) { if (!skipIpv6Check && hostAddr instanceof Inet6Address) {
throw new IllegalArgumentException("IPV6 addresses not supported (" + hostAddr.getHostAddress() + ")"); throw new IllegalArgumentException("IPV6 addresses not supported (" + hostAddr.getHostAddress() + ")");
} }
} catch (UnknownHostException uhe) { } catch (UnknownHostException uhe) {