mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-13 21:50:33 +03:00
keycloak service: ordering for CLI script
Allow update commands in the script to be ordered using `mkOrder`. If we encounter ordered sub-objects we sort them by priority. To implement this we now explicitly pass current node in `recurse`, which also allows us to clean up edge case for top-level node. Also refactor `recurse` to avoid passing result text argument; we weren't tail recursive before anyway.
This commit is contained in:
parent
9bbcc98e30
commit
3c7e78cc6a
1 changed files with 28 additions and 23 deletions
|
@ -441,9 +441,9 @@ in
|
||||||
# with `expression` to evaluate.
|
# with `expression` to evaluate.
|
||||||
prefixExpression = string:
|
prefixExpression = string:
|
||||||
let
|
let
|
||||||
match = (builtins.match ''"\$\{.*}"'' string);
|
matchResult = builtins.match ''"\$\{.*}"'' string;
|
||||||
in
|
in
|
||||||
if match != null then
|
if matchResult != null then
|
||||||
"expression " + string
|
"expression " + string
|
||||||
else
|
else
|
||||||
string;
|
string;
|
||||||
|
@ -508,52 +508,57 @@ in
|
||||||
""
|
""
|
||||||
else
|
else
|
||||||
throw "Unsupported type '${type}' for attribute '${attribute}'!";
|
throw "Unsupported type '${type}' for attribute '${attribute}'!";
|
||||||
|
|
||||||
in
|
in
|
||||||
lib.concatStringsSep ", " (lib.mapAttrsToList makeArg set);
|
lib.concatStringsSep ", " (lib.mapAttrsToList makeArg set);
|
||||||
|
|
||||||
|
|
||||||
/* Recurses into the `attrs` attrset, beginning at the path
|
/* Recurses into the `nodeValue` attrset. Only subattrsets that
|
||||||
resolved from `state.path ++ node`; if `node` is `null`,
|
are JBoss paths, i.e. follows the `key=value` format, are recursed
|
||||||
starts from `state.path`. Only subattrsets that are JBoss
|
|
||||||
paths, i.e. follows the `key=value` format, are recursed
|
|
||||||
into - the rest are considered JBoss attributes / maps.
|
into - the rest are considered JBoss attributes / maps.
|
||||||
*/
|
*/
|
||||||
recurse = state: node:
|
recurse = nodePath: nodeValue:
|
||||||
let
|
let
|
||||||
path = state.path ++ (lib.optional (node != null) node);
|
nodeContent =
|
||||||
|
if builtins.isAttrs nodeValue && nodeValue._type or "" == "order" then
|
||||||
|
nodeValue.content
|
||||||
|
else
|
||||||
|
nodeValue;
|
||||||
isPath = name:
|
isPath = name:
|
||||||
let
|
let
|
||||||
value = lib.getAttrFromPath (path ++ [ name ]) attrs;
|
value = nodeContent.${name};
|
||||||
in
|
in
|
||||||
if (builtins.match ".*([=]).*" name) == [ "=" ] then
|
if (builtins.match ".*([=]).*" name) == [ "=" ] then
|
||||||
if builtins.isAttrs value || value == null then
|
if builtins.isAttrs value || value == null then
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
throw "Parsing path '${lib.concatStringsSep "." (path ++ [ name ])}' failed: JBoss attributes cannot contain '='!"
|
throw "Parsing path '${lib.concatStringsSep "." (nodePath ++ [ name ])}' failed: JBoss attributes cannot contain '='!"
|
||||||
else
|
else
|
||||||
false;
|
false;
|
||||||
jbossPath = "/" + (lib.concatStringsSep "/" path);
|
jbossPath = "/" + lib.concatStringsSep "/" nodePath;
|
||||||
nodeValue = lib.getAttrFromPath path attrs;
|
children = if !builtins.isAttrs nodeContent then {} else nodeContent;
|
||||||
children = if !builtins.isAttrs nodeValue then {} else nodeValue;
|
|
||||||
subPaths = builtins.filter isPath (builtins.attrNames children);
|
subPaths = builtins.filter isPath (builtins.attrNames children);
|
||||||
|
getPriority = name:
|
||||||
|
let value = children.${name};
|
||||||
|
in if value._type or "" == "order" then value.priority else 1000;
|
||||||
|
orderedSubPaths = lib.sort (a: b: getPriority a < getPriority b) subPaths;
|
||||||
jbossAttrs = lib.filterAttrs (name: _: !(isPath name)) children;
|
jbossAttrs = lib.filterAttrs (name: _: !(isPath name)) children;
|
||||||
in
|
text =
|
||||||
state // {
|
if nodeContent != null then
|
||||||
text = state.text + (
|
''
|
||||||
if nodeValue != null then ''
|
|
||||||
if (outcome != success) of ${jbossPath}:read-resource()
|
if (outcome != success) of ${jbossPath}:read-resource()
|
||||||
${jbossPath}:add(${makeArgList jbossAttrs})
|
${jbossPath}:add(${makeArgList jbossAttrs})
|
||||||
end-if
|
end-if
|
||||||
'' + (writeAttributes jbossPath jbossAttrs)
|
'' + writeAttributes jbossPath jbossAttrs
|
||||||
else ''
|
else
|
||||||
|
''
|
||||||
if (outcome == success) of ${jbossPath}:read-resource()
|
if (outcome == success) of ${jbossPath}:read-resource()
|
||||||
${jbossPath}:remove()
|
${jbossPath}:remove()
|
||||||
end-if
|
end-if
|
||||||
'') + (builtins.foldl' recurse { text = ""; inherit path; } subPaths).text;
|
'';
|
||||||
};
|
in text + lib.concatMapStringsSep "\n" (name: recurse (nodePath ++ [name]) children.${name}) orderedSubPaths;
|
||||||
in
|
in
|
||||||
(recurse { text = ""; path = []; } null).text;
|
recurse [] attrs;
|
||||||
|
|
||||||
|
|
||||||
jbossCliScript = pkgs.writeText "jboss-cli-script" (mkJbossScript keycloakConfig');
|
jbossCliScript = pkgs.writeText "jboss-cli-script" (mkJbossScript keycloakConfig');
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue