Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 21 additions & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,14 @@ let
dupFieldRegistry = pkgs.writeText "deploy-targets-dup-field.json" ''
{"svc": {"ports": "notalist", "ports": []}}
'';
# Unhashable restart/class values (issue #6388): arrays/objects
# where validate() expects a string. validate() must report
# them by field, not crash with a TypeError, and one
# crashing-shape service must not suppress another service's
# ordinary field reports.
unhashableRegistry = pkgs.writeText "deploy-targets-unhashable.json" ''
{"bad": {"class": ["systemd"], "restart": ["always"]}, "other": {"class": {"x": 1}, "restart": "sometimes"}}
'';
in
{
packages.deploy = deployPkgs.deploy;
Expand Down Expand Up @@ -1263,6 +1271,19 @@ let
fi
grep -q "duplicate key 'ports'" dup-field-err.txt
test ! -s dup-field-out.txt
if ${deployPkgs.deploy}/bin/deploy list --registry ${unhashableRegistry} > unhash-out.txt 2> unhash-err.txt; then
echo "deploy list accepted a registry with unhashable restart/class values" >&2
exit 1
fi
grep -q "service 'bad': restart must be one of" unhash-err.txt
grep -q "service 'bad': class must be one of" unhash-err.txt
grep -q "service 'other': class must be one of" unhash-err.txt
grep -q "service 'other': restart must be one of" unhash-err.txt
if grep -q "Traceback" unhash-err.txt; then
echo "deploy list crashed with a traceback on unhashable values" >&2
exit 1
fi
test ! -s unhash-out.txt
mkdir -p $out
cp err.txt $out/errors.txt
'';
Expand Down
8 changes: 6 additions & 2 deletions pkgs/deploy/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ def validate(registry):
errors.append(f"{where}: ports must be a list of integers in 1..65535")
elif len(set(ports)) != len(ports):
errors.append(f"{where}: ports must not repeat a port")
if "restart" in defn and defn["restart"] not in RESTART_POLICIES:
if "restart" in defn and not (
isinstance(defn["restart"], str) and defn["restart"] in RESTART_POLICIES
):
errors.append(
f"{where}: restart must be one of {', '.join(sorted(RESTART_POLICIES))}"
)
Expand All @@ -141,7 +143,9 @@ def validate(registry):
errors.append(
f"{where}: targets must be a non-empty list of host/class names"
)
if "class" in defn and defn["class"] not in CLASSES:
if "class" in defn and not (
isinstance(defn["class"], str) and defn["class"] in CLASSES
):
errors.append(f"{where}: class must be one of {', '.join(sorted(CLASSES))}")
return errors

Expand Down