Commit 3647fe03 authored by Penom Nom's avatar Penom Nom
Browse files

update download to encrypt password

parent d60cb676
......@@ -28,6 +28,7 @@ import string, gzip, bz2
import tarfile, tempfile
from shutil import copyfile, rmtree
import re
import base64
class Utils(object):
"""
......@@ -41,6 +42,8 @@ class Utils(object):
CASAVA_FILENAME = { 'sample' : 1, 'barcode' : 2, 'lane' : 3, 'read' : 4, 'package' : 5 }
CASAVA_FILENAME_SEPARATOR = '_'
PASS_KEY = '1234123412341234123412341234'
@staticmethod
def gzip(file, out_dir, delete=False):
"""
......@@ -320,4 +323,22 @@ class Utils(object):
return path_groups
@staticmethod
def encode_passwd(clear):
enc = []
for i in range(len(clear)):
key_c = Utils.PASS_KEY[i % len(Utils.PASS_KEY)]
enc_c = chr((ord(clear[i]) + ord(key_c)) % 256)
enc.append(enc_c)
return base64.urlsafe_b64encode("".join(enc))
@staticmethod
def decode_passwd(enc):
dec = []
enc = base64.urlsafe_b64decode(enc)
for i in range(len(enc)):
key_c = Utils.PASS_KEY[i % len(Utils.PASS_KEY)]
dec_c = chr((256 + ord(enc[i]) - ord(key_c)) % 256)
dec.append(dec_c)
return "".join(dec)
\ No newline at end of file
......@@ -32,8 +32,8 @@ class Download (Workflow):
self.add_multiple_parameter("home_link", "Create a symbolik link in a home directory")
self.add_parameter('username', 'Valid username on the server', type = "localuser" ,required = True, add_to ="home_link")
self.add_parameter('password', 'A password for the usernmae on the server', type="password", required = True, add_to ="home_link")
self.add_parameter('user_directory', 'Destination', default = "/work/", required = True, add_to ="home_link")
self.add_parameter('password', 'A password for the username on the server', type="password", required = True, add_to ="home_link")
self.add_parameter('user_directory', 'Destination', default = "/work/", required = True, add_to ="home_link", type="localdirectory")
self.add_multiple_parameter("local_archive", "Download an archive on your computer")
self.add_parameter('user_email', 'Provide an email to be warned when the process is over', type="email", required = True, add_to ="local_archive")
......
......@@ -19,6 +19,7 @@ import os
import pickle
from jflow.component import Component
from ng6.utils import Utils
from weaver.function import PythonFunction
......@@ -27,8 +28,11 @@ def create_symbolik_link (username, password, ng6_username, data_folder, output_
import pickle
from ng6.config_reader import NG6ConfigReader
from ng6.utils import Utils
from workflows.download.lib.utils import get_directories_structure_and_content, SSH
password = Utils.decode_passwd(password)
try:
fh = open(ids_dump_path, "rb")
prefixed_ids = pickle.load(fh)
......@@ -68,7 +72,7 @@ class CreateSymlink (Component):
self.add_parameter('data_directory', 'data_directory', default = data_directory, required = True)
self.add_parameter('login', 'The login of the user in ng6', type = 'ng6userlogin', default = login)
self.add_parameter('username', 'Valid username on the server', required = True, default = username)
self.add_parameter('password', 'A password for the usernmae on the server', required = True, default = password)
self.add_parameter('password', 'A password for the usernmae on the server', required = True, default = Utils.encode_passwd(password))
self.add_parameter('user_directory', 'Destination', required = True, default = user_directory)
self.add_parameter_list('data_ids', 'Ids or a run from which rawdata will be retrieved', default = data_ids)
self.add_parameter_list('run_ids', 'Ids of run from which all data will be retrieved', default = run_ids)
......
......@@ -43,7 +43,12 @@ def casavadir (dir):
return os.path.abspath(dir)
else:
raise argparse.ArgumentTypeError("Local directory'" + dir + "'does not exists or it's a wrong casava directory structure! Please provide a valid directory path!")
def localdirectory(dir):
if not os.path.isdir(dir):
raise argparse.ArgumentTypeError("The local directory'" + dir + "'does not exists !")
return dir
def ng6adminlogin(login):
t3mysql = t3MySQLdb()
if not t3mysql.is_ng6admin(login) :
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment