aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlice Ferrazzi <alicef@gentoo.org>2017-07-02 10:21:44 +0900
committerAlice Ferrazzi <alicef@gentoo.org>2017-07-02 10:21:44 +0900
commite53cb0960e505c1f451fafd04937cdf4ca26b0fd (patch)
tree9537639e6d5ba8264b34041b6061530461002ec9
parentAdded UserID for divide users (diff)
downloadelivepatch-e53cb0960e505c1f451fafd04937cdf4ca26b0fd.tar.gz
elivepatch-e53cb0960e505c1f451fafd04937cdf4ca26b0fd.tar.bz2
elivepatch-e53cb0960e505c1f451fafd04937cdf4ca26b0fd.zip
Sending UserID and storing it in shelves
-rw-r--r--elivepatch_client/client/checkers.py20
-rw-r--r--elivepatch_client/client/restful.py34
2 files changed, 44 insertions, 10 deletions
diff --git a/elivepatch_client/client/checkers.py b/elivepatch_client/client/checkers.py
index b6ef93a..d5a7b74 100644
--- a/elivepatch_client/client/checkers.py
+++ b/elivepatch_client/client/checkers.py
@@ -11,6 +11,7 @@ import gzip
import os
import os.path
import re
+import shelve
class Kernel(object):
@@ -21,6 +22,7 @@ class Kernel(object):
self.url = url
self.kernel_version = self.get_version()
self.rest_manager = restful.ManaGer(url, self.kernel_version)
+ self.UserID = None
def get_version(self):
tmp = os.uname()[2]
@@ -34,6 +36,7 @@ class Kernel(object):
self.patch = patch_path
def send_config(self):
+ d = shelve.open('userid')
print('conifg path: '+ str(self.config) + 'server url: ' + str(self. url))
print (os.path.basename(self.config))
path, file = (os.path.split(self.config))
@@ -44,13 +47,26 @@ class Kernel(object):
# if the file is .gz the configuration path is the tmp folder uncompressed config file
self.config = os.path.join(path,file)
# we are sending only uncompressed configuration files
- self.rest_manager.send_file(self.config, file, '/elivepatch/api/v1.0/config')
+ replay = self.rest_manager.send_file(self.config, file, '/elivepatch/api/v1.0/config')
+ userid = replay['get_config']['UserID']
+ old_userid = d['UserID']
+ if userid:
+ print(userid)
+ d['UserID'] = userid
+ d.close()
+
def send_patch(self):
+ d = shelve.open('userid')
print("self.patch: "+ self.patch + ' url: '+ self.url)
path, file = (os.path.split(self.patch))
print('file :'+ file)
- self.rest_manager.send_file(self.patch, file, '/elivepatch/api/v1.0/patch')
+ replay = self.rest_manager.send_file(self.patch, file, '/elivepatch/api/v1.0/patch')
+ new_userid = replay['get_patch']['UserID']
+ if new_userid:
+ print(new_userid)
+ d['UserID'] = new_userid
+ d.close()
def build_livepatch(self):
self.rest_manager.build_livepatch()
diff --git a/elivepatch_client/client/restful.py b/elivepatch_client/client/restful.py
index 0aee10d..9329411 100644
--- a/elivepatch_client/client/restful.py
+++ b/elivepatch_client/client/restful.py
@@ -4,10 +4,9 @@
# (c) 2017, Alice Ferrazzi <alice.ferrazzi@gmail.com>
# Distributed under the terms of the GNU General Public License v2 or later
-import json, base64
-import requests
-from requests.auth import HTTPBasicAuth
import time
+import requests
+
class ManaGer(object):
def __init__(self, server_url, kernel_version):
@@ -22,25 +21,44 @@ class ManaGer(object):
def send_file(self, send_file, name_file, api):
url = self.server_url+ api
+ # we are sending the file and the UserID
+ # The server is dividing user by UserID
+ # UserID is generated with python UUID
+ # TODO: add the UserID in the json location instead of headers
+ headers = {'UserID': 'test-00001'}
files = {'file': (name_file, open(send_file, 'rb'), 'multipart/form-data', {'Expires': '0'})}
- r = requests.post(url, files=files)
+ payload = {
+ "KernelVersion" : ("aaaa", 'application/json', {'Expires': '0'}),
+ "LivepatchStatus" : ("not known", 'application/json', {'Expires': '0'}),
+ "UserID" : ("test-00001",'application/json', {'Expires': '0'})
+ }
+ r = requests.post(url, files=files, headers=headers)
+ print('send file: ' + str(r.json()))
+ r_dict = r.json()
+ return r_dict
+
+
def build_livepatch(self):
url = self.server_url+'/elivepatch/api/v1.0/build_livepatch'
payload = {
- 'KernelVersion': self.kernel_version
+ 'KernelVersion': self.kernel_version,
+ 'LivepatchStatus' : 'no idea',
+ 'UserID' : 'test-0000'
}
r = requests.post(url, json=payload)
- print(r.text)
+ # print(r.text)
print(r.json())
def get_livepatch(self):
from io import BytesIO
url = self.server_url+'/elivepatch/api/v1.0/get_livepatch'
payload = {
- 'KernelVersion': self.kernel_version
+ 'KernelVersion': self.kernel_version,
+ 'LivepatchStatus' : 'no idea',
+ 'UserID' : 'test-0000'
}
- r = requests.get(url)
+ r = requests.get(url, json=payload)
if r.status_code == requests.codes.ok: # livepatch returned ok
b= BytesIO(r.content)
with open('myfile.ko', 'wb') as out: