From 97e5ce4344e5f37393089f7dc904b0c528499375 Mon Sep 17 00:00:00 2001 From: streambinder Date: Thu, 26 Sep 2019 12:23:31 +0200 Subject: [PATCH] internal: backend: sftp: support user@domain parsing as user --- internal/backend/sftp/config.go | 7 +++++-- internal/backend/sftp/config_test.go | 8 +++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/internal/backend/sftp/config.go b/internal/backend/sftp/config.go index 90fe52c39..2860a479e 100644 --- a/internal/backend/sftp/config.go +++ b/internal/backend/sftp/config.go @@ -56,8 +56,11 @@ func ParseConfig(s string) (interface{}, error) { host = data[0] dir = data[1] // split user and host at the "@" - data = strings.SplitN(host, "@", 2) - if len(data) == 2 { + data = strings.SplitN(host, "@", 3) + if len(data) == 3 { + user = data[0] + "@" + data[1] + host = data[2] + } else if len(data) == 2 { user = data[0] host = data[1] } diff --git a/internal/backend/sftp/config_test.go b/internal/backend/sftp/config_test.go index 44439005e..acf07e4e7 100644 --- a/internal/backend/sftp/config_test.go +++ b/internal/backend/sftp/config_test.go @@ -1,6 +1,8 @@ package sftp -import "testing" +import ( + "testing" +) var configTests = []struct { in string @@ -41,6 +43,10 @@ var configTests = []struct { "sftp:user@host:/dir/subdir", Config{User: "user", Host: "host", Path: "/dir/subdir"}, }, + { + "sftp:user@domain@host:/dir/subdir", + Config{User: "user@domain", Host: "host", Path: "/dir/subdir"}, + }, { "sftp:host:../dir/subdir", Config{Host: "host", Path: "../dir/subdir"},