use correct ordering for haproxy config
This commit is contained in:
parent
a6eba63f5f
commit
9407df4eb5
1 changed files with 21 additions and 2 deletions
|
@ -24,19 +24,34 @@ let
|
||||||
headerFn = if hasAttr "header" match then match.header else null;
|
headerFn = if hasAttr "header" match then match.header else null;
|
||||||
header = optional (headerFn != null) (headerFn k);
|
header = optional (headerFn != null) (headerFn k);
|
||||||
trailer = optional (headerFn != null) "";
|
trailer = optional (headerFn != null) "";
|
||||||
|
content = header ++ indent (augmentedContent "${fieldName}.${k}" rules (parent ++ [k]) v) ++ trailer;
|
||||||
in
|
in
|
||||||
if rule != null
|
if rule != null
|
||||||
then rule k parent v
|
then rule k parent v
|
||||||
else
|
else
|
||||||
assert assertMsg (isAttrs v) "attempt to apply rules on key '${toString k}' which is a '${typeOf v}' but should be a set:\n${toString v}";
|
assert assertMsg (isAttrs v) "attempt to apply rules on key '${toString k}' which is a '${typeOf v}' but should be a set:\n${toString v}";
|
||||||
header ++ indent (augmentedContent "${fieldName}.${k}" rules (parent ++ [k]) v) ++ trailer;
|
if hasAttr "order" match then
|
||||||
|
{
|
||||||
|
inherit (match) order;
|
||||||
|
inherit content;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
content;
|
||||||
|
|
||||||
augmented = mapAttrsToList (augment parent) (
|
augmented = mapAttrsToList (augment parent) (
|
||||||
assert assertMsg (isAttrs set) "attempt to apply rules on field ${fieldName} having type '${typeOf set}':\n${toString set}";
|
assert assertMsg (isAttrs set) "attempt to apply rules on field ${fieldName} having type '${typeOf set}':\n${toString set}";
|
||||||
set
|
set
|
||||||
);
|
);
|
||||||
|
|
||||||
|
sortAugmented = sort (a: b:
|
||||||
|
(isAttrs a && hasAttr "order" a)
|
||||||
|
&& (isAttrs b && hasAttr "order" b)
|
||||||
|
&& a.order < b.order
|
||||||
|
);
|
||||||
|
|
||||||
|
onlyContent = (x: if isAttrs x && hasAttr "content" x then x.content else x);
|
||||||
in
|
in
|
||||||
flatten augmented;
|
flatten (map onlyContent (sortAugmented augmented));
|
||||||
|
|
||||||
updateByPath = path: fn: set:
|
updateByPath = path: fn: set:
|
||||||
if hasAttrByPath path set then
|
if hasAttrByPath path set then
|
||||||
|
@ -94,6 +109,7 @@ let
|
||||||
in [
|
in [
|
||||||
{
|
{
|
||||||
match = k: parent: v: k == "defaults";
|
match = k: parent: v: k == "defaults";
|
||||||
|
order = 2;
|
||||||
indent = " ";
|
indent = " ";
|
||||||
header = k: k;
|
header = k: k;
|
||||||
rules = [
|
rules = [
|
||||||
|
@ -105,12 +121,14 @@ let
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
match = k: parent: v: k == "global";
|
match = k: parent: v: k == "global";
|
||||||
|
order = 1;
|
||||||
indent = " ";
|
indent = " ";
|
||||||
header = k: k;
|
header = k: k;
|
||||||
rules = [];
|
rules = [];
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
match = k: parent: v: k == "frontend";
|
match = k: parent: v: k == "frontend";
|
||||||
|
order = 3;
|
||||||
rules = [
|
rules = [
|
||||||
{
|
{
|
||||||
match = k: parent: v: true;
|
match = k: parent: v: true;
|
||||||
|
@ -159,6 +177,7 @@ let
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
match = k: parent: v: k == "backend";
|
match = k: parent: v: k == "backend";
|
||||||
|
order = 4;
|
||||||
rules = [
|
rules = [
|
||||||
{
|
{
|
||||||
match = k: parent: v: true;
|
match = k: parent: v: true;
|
||||||
|
|
Loading…
Reference in a new issue