Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add type check to labels maps in FIND and FETCH #1394

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions warp10/src/main/java/io/warp10/script/functions/FETCH.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2018-2024 SenX S.A.S.
// Copyright 2018-2025 SenX S.A.S.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -526,7 +526,17 @@ public void close() throws Exception {}
} else {
clsSels.add(params.get(PARAM_CLASS).toString());

Map<String, String> labelSelectors = new LinkedHashMap<>((Map<String, String>) params.get(PARAM_LABELS));
Object o = params.get(FETCH.PARAM_LABELS);
if (!(o instanceof Map)) {
throw new WarpScriptException("Label selectors must be a map.");
pi-r-p marked this conversation as resolved.
Show resolved Hide resolved
pi-r-p marked this conversation as resolved.
Show resolved Hide resolved
}
for (Entry<Object, Object> entry: ((Map<Object, Object>) o).entrySet()) {
if (!(entry.getKey() instanceof String) || !(entry.getValue() instanceof String)) {
throw new WarpScriptException(getName() + " keys and values of label selector must be STRING.");
pi-r-p marked this conversation as resolved.
Show resolved Hide resolved
}
}

Map<String, String> labelSelectors = new LinkedHashMap<>((Map<String, String>) o);
labelSelectors.remove(Constants.PRODUCER_LABEL);
labelSelectors.remove(Constants.OWNER_LABEL);
labelSelectors.remove(Constants.APPLICATION_LABEL);
Expand Down
20 changes: 18 additions & 2 deletions warp10/src/main/java/io/warp10/script/functions/FIND.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2018-2024 SenX S.A.S.
// Copyright 2018-2025 SenX S.A.S.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -241,7 +241,17 @@ public Object apply(WarpScriptStack stack) throws WarpScriptException {
}
} else if (params.containsKey(FETCH.PARAM_CLASS) && params.containsKey(FETCH.PARAM_LABELS)) {
classSelector = (String) params.get(FETCH.PARAM_CLASS);
labelSelectors = new LinkedHashMap<String,String>((Map<String,String>) params.get(FETCH.PARAM_LABELS));
Object o = params.get(FETCH.PARAM_LABELS);
if (!(o instanceof Map)) {
throw new WarpScriptException("Label selectors must be a map.");
pi-r-p marked this conversation as resolved.
Show resolved Hide resolved
}
for (Entry<Object, Object> entry: ((Map<Object, Object>) o).entrySet()) {
if (!(entry.getKey() instanceof String) || !(entry.getValue() instanceof String)) {
throw new WarpScriptException(getName() + " keys and values of label selector must be STRING.");
pi-r-p marked this conversation as resolved.
Show resolved Hide resolved
}
}

labelSelectors = new LinkedHashMap<String,String>((Map<String,String>) o);
} else {
throw new WarpScriptException(getName() + " missing parameters '" + FETCH.PARAM_CLASS + "', '" + FETCH.PARAM_LABELS + "', '" + FETCH.PARAM_SELECTOR + "' or '" + FETCH.PARAM_SELECTORS + "'.");
}
Expand Down Expand Up @@ -308,6 +318,12 @@ public Object apply(WarpScriptStack stack) throws WarpScriptException {
throw new WarpScriptException("Label selectors must be a map.");
}

for (Entry<Object, Object> entry: ((Map<Object, Object>) oLabelsSelector).entrySet()) {
if (!(entry.getKey() instanceof String) || !(entry.getValue() instanceof String)) {
throw new WarpScriptException(getName() + " keys and values of label selector must be STRING.");
pi-r-p marked this conversation as resolved.
Show resolved Hide resolved
}
}

labelSelectors = new LinkedHashMap<String,String>((Map<String,String>) oLabelsSelector);

//
Expand Down