From 4c38ae86a93e4e309ef008a2a4be7a2863255f43 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:31:04 -0500 Subject: [PATCH] fix ldap search command --- modules/common/shell/work.nix | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/common/shell/work.nix b/modules/common/shell/work.nix index d371882..3df7056 100644 --- a/modules/common/shell/work.nix +++ b/modules/common/shell/work.nix @@ -13,7 +13,11 @@ let ldap_scheme = "ldaps"; magic_prefix = "take"; - ldap_port = 636; + ldap_port = 3269; + jq_parse = pkgs.writeShellScriptBin "ljq" '' + jq --slurp \ + --raw-input 'split("\n\n")|map(split("\n")|map(select(.[0:1]!="#" and length>0)) |select(length > 0)|map(capture("^(?[^:]*:?): *(?.*)") |if .key[-1:.key|length] == ":" then .key=.key[0:-1]|.value=(.value|@base64d) else . end)| group_by(.key) | map({key:.[0].key,value:(if .|length > 1 then [.[].value] else .[].value end)}) | from_entries)' | jq -r 'del(.[].thumbnailPhoto)' + ''; ldap_script = pkgs.writeShellScriptBin "ldap" '' if ! [ "$LDAP_HOST" ]; then echo "No LDAP_HOST specified!" @@ -22,13 +26,13 @@ SEARCH_FILTER="$@" ldapsearch -LLL \ -B -o ldif-wrap=no \ + -E pr=5000/prompt \ -H "${ldap_scheme}://''${LDAP_HOST}:${builtins.toString ldap_port}" \ -D "${pkgs.lib.toUpper magic_prefix}2\\${pkgs.lib.toLower config.user}" \ - -w "$(${pkgs._1password}/bin/op item get T2 --fields label=password)" \ + -w "$(${pkgs._1password-cli}/bin/op item get T2 --fields label=password --reveal)" \ -b "dc=''${LDAP_HOST//./,dc=}" \ -s "sub" -x "(cn=''${SEARCH_FILTER})" \ - | jq --slurp \ - --raw-input 'split("\n\n")|map(split("\n")|map(select(.[0:1]!="#" and length>0)) |select(length > 0)|map(capture("^(?[^:]*:?): *(?.*)") |if .key[-1:.key|length] == ":" then .key=.key[0:-1]|.value=(.value|@base64d) else . end)| group_by(.key) | map({key:.[0].key,value:(if .|length > 1 then [.[].value] else .[].value end)}) | from_entries)' | jq -r 'del(.[].thumbnailPhoto)' + | ${jq_parse}/bin/ljq ''; ldapm_script = pkgs.writeShellScriptBin "ldapm" '' if ! [ "$LDAP_HOST" ]; then @@ -49,6 +53,7 @@ ldap_script ldapm_script ldapg_script + jq_parse ]; }; }