mod/ssh-keys-import: $SSHKeysImportFile: let :deserialize split the fields

This commit is contained in:
Christian Hesse 2024-11-08 08:30:07 +01:00
parent 9c945b1a32
commit 0837391c38

View file

@ -72,7 +72,6 @@
:local FileName [ :tostr $1 ]; :local FileName [ :tostr $1 ];
:local User [ :tostr $2 ]; :local User [ :tostr $2 ];
:global CharacterReplace;
:global EitherOr; :global EitherOr;
:global LogPrint; :global LogPrint;
:global ParseKeyValueStore; :global ParseKeyValueStore;
@ -90,20 +89,18 @@
} }
:local Keys [ :tolf [ /file/get $FileName contents ] ]; :local Keys [ :tolf [ /file/get $FileName contents ] ];
:foreach Line in=[ :deserialize $Keys delimiter="\n" from=dsv options=dsv.plain ] do={ :foreach KeyVal in=[ :deserialize $Keys delimiter=" " from=dsv options=dsv.plain ] do={
:set Line ($Line->0);
:local Continue false; :local Continue false;
:local KeyVal [ :toarray [ $CharacterReplace $Line " " "," ] ];
:if ($KeyVal->0 = "ssh-ed25519" || $KeyVal->0 = "ssh-rsa") do={ :if ($KeyVal->0 = "ssh-ed25519" || $KeyVal->0 = "ssh-rsa") do={
:do { :do {
$SSHKeysImport $Line $User; $SSHKeysImport ($KeyVal->0 . " " . $KeyVal->1 . " " . $KeyVal->2) $User;
} on-error={ } on-error={
$LogPrint warning $0 ("Failed importing key for user '" . $User . "'."); $LogPrint warning $0 ("Failed importing key for user '" . $User . "'.");
} }
:set Continue true; :set Continue true;
} }
:if ($Continue = false && $KeyVal->0 = "#") do={ :if ($Continue = false && $KeyVal->0 = "#") do={
:set User [ $EitherOr ([ $ParseKeyValueStore [ :pick $Line 2 [ :len $Line ] ] ]->"user") $User ]; :set User [ $EitherOr ([ $ParseKeyValueStore ($KeyVal->1) ]->"user") $User ];
:set Continue true; :set Continue true;
} }
:if ($Continue = false && [ :len ($KeyVal->0) ] > 0) do={ :if ($Continue = false && [ :len ($KeyVal->0) ] > 0) do={