diff options
author | Alice Ferrazzi <alicef@gentoo.org> | 2017-06-21 05:23:15 +0900 |
---|---|---|
committer | Alice Ferrazzi <alicef@gentoo.org> | 2017-06-21 05:23:15 +0900 |
commit | 12416dd19cfcf537467fab6963c2a6deefcd7648 (patch) | |
tree | 6ec88ea02c9b2f30336fe9b9655cf051de70c851 | |
parent | fix for getting the correct filename (diff) | |
download | elivepatch-12416dd19cfcf537467fab6963c2a6deefcd7648.tar.gz elivepatch-12416dd19cfcf537467fab6963c2a6deefcd7648.tar.bz2 elivepatch-12416dd19cfcf537467fab6963c2a6deefcd7648.zip |
if config file is compressed uncompress it
-rw-r--r-- | elivepatch_client/client/checkers.py | 39 | ||||
-rw-r--r-- | elivepatch_client/client/restful.py | 8 |
2 files changed, 40 insertions, 7 deletions
diff --git a/elivepatch_client/client/checkers.py b/elivepatch_client/client/checkers.py index cf94ad7..9c7b812 100644 --- a/elivepatch_client/client/checkers.py +++ b/elivepatch_client/client/checkers.py @@ -2,7 +2,10 @@ import os from git import Repo from elivepatch_client.client import restful - +import gzip +import glob +import os +import os.path class Kernel(object): @@ -26,10 +29,18 @@ class Kernel(object): pass def send_config(self, url): - print(str(self.config)+ str(url)) + print('conifg path: '+ str(self.config) + 'server url: ' + str(url)) print (os.path.basename(self.config)) path, file = (os.path.split(self.config)) + file_extension = os.path.splitext(file)[1] + if file_extension == ".gz": + print('gz extension') + f_action =FileAction(path, file) + path, file = f_action.ungz() + # if the file is .gz the configuration path is the tmp folder uncompressed config file + self.config = path +'/'+file rest_manager = restful.ManaGer(url) + # we are sending only uncompressed configuration files rest_manager.send_config(self.config, file) pass @@ -46,3 +57,27 @@ class CVE(object): def set_repo(self, git_url, repo_dir): self.git_url = git_url self.repo_dir = repo_dir + + +class FileAction(object): + + def __init__(self, path, filename): + self.path = path + self.filename = filename + pass + + def ungz(self): + path_to_store = None + get_file_path = self.path +'/'+self.filename + store_file_path = '/tmp/'+self.filename + print('file_path: '+ get_file_path) + if not os.path.isdir(get_file_path): + with gzip.open(get_file_path, 'rb') as in_file: + s = in_file.read() + # Store uncompressed file + path_to_store = store_file_path[:-3] # remove the filename extension + with open(path_to_store, 'w') as f: + f.write(s) + print('working') + path, file = (os.path.split(path_to_store)) + return path, file diff --git a/elivepatch_client/client/restful.py b/elivepatch_client/client/restful.py index 0482bbb..b233144 100644 --- a/elivepatch_client/client/restful.py +++ b/elivepatch_client/client/restful.py @@ -4,21 +4,19 @@ import json, base64 import requests from requests.auth import HTTPBasicAuth + class ManaGer(object): def __init__(self, server_url): self.server_url = server_url def version(self): url = self.server_url + '/elivepatch/api/v1.0/agent' - auth_user='elivepatch' - auth_passwd='default' - r = requests.get(url, auth=HTTPBasicAuth(auth_user, auth_passwd)) + r = requests.get(url) print(r.text) print(r.json()) def send_config(self, send_file, name_file): url = self.server_url+'/elivepatch/api/v1.0/config' - headers = {'elivepatch': 'password'} files = {'file': (name_file, open(send_file, 'rb'), 'multipart/form-data', {'Expires': '0'})} - r = requests.post(url, files=files, headers=headers) + r = requests.post(url, files=files) |