aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2024-04-11 09:34:57 +0200
committerHarald Musum <musum@yahooinc.com>2024-04-11 09:34:57 +0200
commit73e63a0489263a1c7671e6f3cb29d31dcdd09c37 (patch)
treea2e589b79be05b5558cdd9d03ff089f1690ea5b4 /config-model/src/main/java/com/yahoo
parented76cd45f86c8af9431860a9ac7c40fc59fb9e3c (diff)
Validate url for models
Diffstat (limited to 'config-model/src/main/java/com/yahoo')
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/component/Model.java14
1 files changed, 13 insertions, 1 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/component/Model.java b/config-model/src/main/java/com/yahoo/vespa/model/container/component/Model.java
index 7d6285d00c1..3a8e52c92a8 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/component/Model.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/component/Model.java
@@ -13,6 +13,7 @@ import com.yahoo.vespa.model.container.xml.ModelIdResolver;
import org.w3c.dom.Element;
import java.net.URI;
+import java.net.URISyntaxException;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
@@ -51,11 +52,22 @@ class Model {
static Model fromXml(DeployState ds, Element model, Set<String> requiredTags) {
var modelId = XmlHelper.getOptionalAttribute(model, "model-id").orElse(null);
- var url = XmlHelper.getOptionalAttribute(model, "url").map(URI::create).orElse(null);
+ var url = XmlHelper.getOptionalAttribute(model, "url").map(Model::parseUrl).orElse(null);
var path = XmlHelper.getOptionalAttribute(model, "path").map(Path::fromString).orElse(null);
return new Model(ds, model.getTagName(), modelId, url, path, requiredTags);
}
+ private static URI parseUrl(String url) {
+ try {
+ var uri = new URI(url);
+ if ( ! uri.isAbsolute())
+ throw new IllegalArgumentException("Invalid url '" + url + "': url has no 'scheme' component");
+ return uri;
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException("Invalid url '" + url + "':" + e.getMessage());
+ }
+ }
+
/** Return tokenizer model from XML if specified, alternatively use model id for ONNX model with suffix '-vocab' appended */
static Model fromXmlOrImplicitlyFromOnnxModel(
DeployState ds, Element parent, Model onnxModel, String paramName, Set<String> requiredTags) {