1
0
Fork 0
mirror of https://cgit.krebsco.de/krops synced 2024-11-23 03:29:48 +01:00

ssh: support using ssh-configured user

Let ssh use the user configured in its configuration files when the
target user is set to the empty string.

Closes https://github.com/krebs/krops/issues/2
This commit is contained in:
tv 2019-11-29 00:01:37 +01:00
parent 2e94e6eb24
commit d9d3c5072a
3 changed files with 10 additions and 8 deletions

View file

@ -44,7 +44,7 @@ let {
mkTarget = s: let mkTarget = s: let
default = defVal: val: if val != null then val else defVal; default = defVal: val: if val != null then val else defVal;
parse = lib.match "(([^@]+)@)?(([^:/]+))?(:([^/]+))?(/.*)?" s; parse = lib.match "(([^@]*)@)?(([^:/]+))?(:([^/]+))?(/.*)?" s;
elemAt' = xs: i: if lib.length xs > i then lib.elemAt xs i else null; elemAt' = xs: i: if lib.length xs > i then lib.elemAt xs i else null;
in { in {
user = default (lib.getEnv "LOGNAME") (elemAt' parse 1); user = default (lib.getEnv "LOGNAME") (elemAt' parse 1);

View file

@ -20,9 +20,9 @@ in
remoteCommand = target: command: remoteCommand = target: command:
exec "build.${target.host}" rec { exec "build.${target.host}" rec {
filename = "${openssh}/bin/ssh"; filename = "${openssh}/bin/ssh";
argv = [ argv = lib.flatten [
filename filename
"-l" target.user (lib.optionals (target.user != "") ["-l" target.user])
"-p" target.port "-p" target.port
"-t" "-t"
target.host target.host

View file

@ -162,8 +162,10 @@ let
--delete-excluded \ --delete-excluded \
"$source_path" \ "$source_path" \
${quote ( ${quote (
optionalString (!isLocalTarget target) optionalString (!isLocalTarget target) (
"${target.user}@${target.host}:" + (optionalString (target.user != "") "${target.user}@") +
"${target.host}:"
) +
target.path target.path
)} \ )} \
>&2 >&2
@ -176,13 +178,13 @@ let
${ssh' target} ${quote target.host} ${quote script} ${ssh' target} ${quote target.host} ${quote script}
''; '';
ssh' = target: concatMapStringsSep " " quote [ ssh' = target: concatMapStringsSep " " quote (flatten [
"${openssh}/bin/ssh" "${openssh}/bin/ssh"
"-l" target.user (optionals (target.user != "") ["-l" target.user])
"-o" "ControlPersist=no" "-o" "ControlPersist=no"
"-p" target.port "-p" target.port
"-T" "-T"
]; ]);
in in