mirror of
https://github.com/nmasur/dotfiles
synced 2024-11-25 11:25:37 +00:00
remove magic prefix from ldap script
This commit is contained in:
parent
1d1d5014a0
commit
3ef36c4873
@ -12,34 +12,36 @@
|
|||||||
home.packages =
|
home.packages =
|
||||||
let
|
let
|
||||||
ldap_scheme = "ldaps";
|
ldap_scheme = "ldaps";
|
||||||
magic_number = "2";
|
|
||||||
magic_end_seq = "corp";
|
|
||||||
magic_prefix = "take";
|
magic_prefix = "take";
|
||||||
ldap_host = "${magic_prefix}${magic_number}.t${magic_number}.${magic_end_seq}";
|
|
||||||
ldap_port = 636;
|
ldap_port = 636;
|
||||||
ldap_dc_1 = "${magic_prefix}${magic_number}";
|
|
||||||
ldap_dc_2 = "t${magic_number}";
|
|
||||||
ldap_dc_3 = magic_end_seq;
|
|
||||||
ldap_script = pkgs.writeShellScriptBin "ldap" ''
|
ldap_script = pkgs.writeShellScriptBin "ldap" ''
|
||||||
# if ! [ "$LDAP_HOST" ]; then
|
if ! [ "$LDAP_HOST" ]; then
|
||||||
# echo "No LDAP_HOST specified!"
|
echo "No LDAP_HOST specified!"
|
||||||
# exit 1
|
exit 1
|
||||||
# fi
|
fi
|
||||||
SEARCH_FILTER="$@"
|
SEARCH_FILTER="$@"
|
||||||
ldapsearch -LLL \
|
ldapsearch -LLL \
|
||||||
-B -o ldif-wrap=no \
|
-B -o ldif-wrap=no \
|
||||||
-H "${ldap_scheme}://${ldap_host}:${builtins.toString ldap_port}" \
|
-H "${ldap_scheme}://''${LDAP_HOST}:${builtins.toString ldap_port}" \
|
||||||
-D "${pkgs.lib.toUpper magic_prefix}${magic_number}\\${pkgs.lib.toLower config.user}" \
|
-D "${pkgs.lib.toUpper magic_prefix}2\\${pkgs.lib.toLower config.user}" \
|
||||||
-w "$(${pkgs._1password}/bin/op item get T${magic_number} --fields label=password)" \
|
-w "$(${pkgs._1password}/bin/op item get T2 --fields label=password)" \
|
||||||
-b "DC=${ldap_dc_1},DC=${ldap_dc_2},DC=${ldap_dc_3}" \
|
-b "dc=''${LDAP_HOST//./,dc=}" \
|
||||||
-s "sub" -x "(cn=$SEARCH_FILTER)" \
|
-s "sub" -x "(cn=''${SEARCH_FILTER})" \
|
||||||
| jq --slurp \
|
| jq --slurp \
|
||||||
--raw-input 'split("\n\n")|map(split("\n")|map(select(.[0:1]!="#" and length>0)) |select(length > 0)|map(capture("^(?<key>[^:]*:?): *(?<value>.*)") |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)'
|
--raw-input 'split("\n\n")|map(split("\n")|map(select(.[0:1]!="#" and length>0)) |select(length > 0)|map(capture("^(?<key>[^:]*:?): *(?<value>.*)") |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)'
|
||||||
'';
|
'';
|
||||||
ldapm_script = pkgs.writeShellScriptBin "ldapm" ''
|
ldapm_script = pkgs.writeShellScriptBin "ldapm" ''
|
||||||
|
if ! [ "$LDAP_HOST" ]; then
|
||||||
|
echo "No LDAP_HOST specified!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
${ldap_script}/bin/ldap "$@" | jq '[ .[].memberOf] | add'
|
${ldap_script}/bin/ldap "$@" | jq '[ .[].memberOf] | add'
|
||||||
'';
|
'';
|
||||||
ldapg_script = pkgs.writeShellScriptBin "ldapg" ''
|
ldapg_script = pkgs.writeShellScriptBin "ldapg" ''
|
||||||
|
if ! [ "$LDAP_HOST" ]; then
|
||||||
|
echo "No LDAP_HOST specified!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
${ldap_script}/bin/ldap "$@" | jq '[ .[].member] | add'
|
${ldap_script}/bin/ldap "$@" | jq '[ .[].member] | add'
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
|
Loading…
Reference in New Issue
Block a user