From e4f3a180c885ccaa8f3d65d649b0b0f663d8f107 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Wed, 28 Dec 2016 15:56:17 +0800 Subject: [PATCH] add random string. Signed-off-by: Bo-Yi Wu --- glide.lock | 8 ++++++-- glide.yaml | 3 +++ plugin.go | 7 ++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/glide.lock b/glide.lock index 0f96798..c077f46 100644 --- a/glide.lock +++ b/glide.lock @@ -1,6 +1,10 @@ -hash: 5e81eac084616ea98e685364cb3bc81054c8098980b087671777d5a378fbca42 -updated: 2016-12-28T11:09:15.754250988+08:00 +hash: 324c76f4ece1989f584ec84aab8252020da4dcbc20e38990465a9a0b7400f8ec +updated: 2016-12-28T15:52:54.896825557+08:00 imports: +- name: github.com/appleboy/com + version: c2e1fea1b771a26cb55774843ebd8955d723ee4e + subpackages: + - random - name: github.com/joho/godotenv version: a01a834e1654b4c9ca5b3ad05159445cc9c7ad08 subpackages: diff --git a/glide.yaml b/glide.yaml index 2e5bb04..c9112f9 100644 --- a/glide.yaml +++ b/glide.yaml @@ -10,6 +10,9 @@ import: subpackages: - ssh - ssh/agent +- package: github.com/appleboy/com + subpackages: + - random testImport: - package: github.com/stretchr/testify version: ^1.1.4 diff --git a/plugin.go b/plugin.go index e9ab16c..35530b1 100644 --- a/plugin.go +++ b/plugin.go @@ -11,6 +11,7 @@ import ( "strings" "sync" + "github.com/appleboy/com/random" "github.com/appleboy/drone-scp/easyssh" ) @@ -79,19 +80,15 @@ func (p Plugin) log(host string, message ...interface{}) { func (p Plugin) Exec() error { if len(p.Config.Host) == 0 || len(p.Config.Username) == 0 || (len(p.Config.Password) == 0 && len(p.Config.Key) == 0) { - log.Println("missing ssh config (Host, Username, Password or Key)") - return errors.New("missing ssh config (Host, Username, Password or Key)") } if len(p.Config.Source) == 0 || len(p.Config.Target) == 0 { - log.Println("missing source or target config") - return errors.New("missing source or target config") } files := trimPath(p.Config.Source) - dest := fmt.Sprintf("%s-%s.tar", p.Repo.Name, p.Build.Commit[:7]) + dest := fmt.Sprintf("%s.tar", random.String(10)) // create a temporary file for the archive dir, err := ioutil.TempDir("", "")