From 67aa3781de6e7cd62a7cc360152fa68a2693fc02 Mon Sep 17 00:00:00 2001 From: Dekel Date: Thu, 6 Dec 2018 09:59:59 +0200 Subject: [PATCH 1/5] support ftp content --- services/ftp/config.json | 10 +++++++++- services/ftp/ftp_service.py | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/services/ftp/config.json b/services/ftp/config.json index e675943d..14ad69ca 100644 --- a/services/ftp/config.json +++ b/services/ftp/config.json @@ -20,5 +20,13 @@ "label": "FTP Server", "description": "An empty FTP server.", "conflicts_with": [] - } + }, + "parameters": [ + { + "type": "file", + "value": "ftp_content", + "label": "FTP Content", + "required": false + } + ] } diff --git a/services/ftp/ftp_service.py b/services/ftp/ftp_service.py index 1aa0f867..e28c4c7e 100644 --- a/services/ftp/ftp_service.py +++ b/services/ftp/ftp_service.py @@ -6,6 +6,9 @@ import os import shutil import ftplib +import base64 +import StringIO +import zipfile from pyftpdlib.handlers import FTPHandler from pyftpdlib.servers import FTPServer @@ -167,6 +170,11 @@ def __init__(self, *args, **kwargs): def prepare_temp_dir(self): """Create a temp dir.""" self.temp_dir = tempfile.mkdtemp() + content = self.service_args.get("ftp_content") + if content: + file_obj = StringIO.StringIO(base64.b64decode(content)) + z = zipfile.ZipFile(file_obj, "r") + z.extractall(self.temp_dir) def delete_temp_dir(self): """Delete the temp dir that we created.""" From e6edfbafc278d24b753ce113c8c9f45c2c86f168 Mon Sep 17 00:00:00 2001 From: Dekel Date: Thu, 6 Dec 2018 10:59:25 +0200 Subject: [PATCH 2/5] support both honeycomb and mazerunner --- services/ftp/ftp_service.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/services/ftp/ftp_service.py b/services/ftp/ftp_service.py index e28c4c7e..ba41d4e2 100644 --- a/services/ftp/ftp_service.py +++ b/services/ftp/ftp_service.py @@ -172,7 +172,10 @@ def prepare_temp_dir(self): self.temp_dir = tempfile.mkdtemp() content = self.service_args.get("ftp_content") if content: - file_obj = StringIO.StringIO(base64.b64decode(content)) + if os.path.exists(content): + file_obj = open(content, "r") + else: + file_obj = StringIO.StringIO(base64.b64decode(content)) z = zipfile.ZipFile(file_obj, "r") z.extractall(self.temp_dir) From d89ddf5a6164cc6ff8331f01e6ce576fb4997cae Mon Sep 17 00:00:00 2001 From: Dekel Date: Sun, 9 Dec 2018 15:56:30 +0200 Subject: [PATCH 3/5] fixed py3 --- services/ftp/ftp_service.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/services/ftp/ftp_service.py b/services/ftp/ftp_service.py index ba41d4e2..1b6a26a1 100644 --- a/services/ftp/ftp_service.py +++ b/services/ftp/ftp_service.py @@ -7,8 +7,11 @@ import shutil import ftplib import base64 -import StringIO import zipfile +try: + from StringIO import StringIO +except ImportError: + from io import StringIO from pyftpdlib.handlers import FTPHandler from pyftpdlib.servers import FTPServer @@ -175,7 +178,7 @@ def prepare_temp_dir(self): if os.path.exists(content): file_obj = open(content, "r") else: - file_obj = StringIO.StringIO(base64.b64decode(content)) + file_obj = StringIO(base64.b64decode(content)) z = zipfile.ZipFile(file_obj, "r") z.extractall(self.temp_dir) From 5b8ef464d56aadc148bfb703fefd4e6200ee023d Mon Sep 17 00:00:00 2001 From: Dekel Date: Sun, 9 Dec 2018 16:16:33 +0200 Subject: [PATCH 4/5] pr - help text --- services/ftp/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/ftp/config.json b/services/ftp/config.json index 14ad69ca..da962c2d 100644 --- a/services/ftp/config.json +++ b/services/ftp/config.json @@ -25,7 +25,7 @@ { "type": "file", "value": "ftp_content", - "label": "FTP Content", + "label": "FTP Content - optional zip file containing the content for the ftp service", "required": false } ] From 4fac0e959ccbba68d5c624b0be5881e9e90191c6 Mon Sep 17 00:00:00 2001 From: Omer Cohen Date: Sun, 9 Dec 2018 17:27:42 +0200 Subject: [PATCH 5/5] Update services/ftp/config.json pr Co-Authored-By: dekelb --- services/ftp/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/ftp/config.json b/services/ftp/config.json index da962c2d..42d93a20 100644 --- a/services/ftp/config.json +++ b/services/ftp/config.json @@ -25,7 +25,7 @@ { "type": "file", "value": "ftp_content", - "label": "FTP Content - optional zip file containing the content for the ftp service", + "label": "FTP Content - Optional path or a base64 encoded string of a zip file containing the content for the ftp service", "required": false } ]