aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlice Ferrazzi <alicef@gentoo.org>2017-07-16 23:03:38 +0900
committerAlice Ferrazzi <alicef@gentoo.org>2017-07-16 23:03:38 +0900
commitd6c0397c9806860fa206217ab1258fedc42b0322 (patch)
treea07f90048288456954810f757baf87c6d0711ad6
parentsetting uuid from the client (diff)
downloadelivepatch-d6c0397c9806860fa206217ab1258fedc42b0322.tar.gz
elivepatch-d6c0397c9806860fa206217ab1258fedc42b0322.tar.bz2
elivepatch-d6c0397c9806860fa206217ab1258fedc42b0322.zip
function for checking uuid validity
and fixed some variable name
-rw-r--r--elivepatch_client/client/checkers.py31
-rw-r--r--elivepatch_server/resources/dispatcher.py29
2 files changed, 32 insertions, 28 deletions
diff --git a/elivepatch_client/client/checkers.py b/elivepatch_client/client/checkers.py
index 318e174..3635291 100644
--- a/elivepatch_client/client/checkers.py
+++ b/elivepatch_client/client/checkers.py
@@ -25,40 +25,43 @@ class Kernel(object):
Class for manage the kernels files
"""
- def __init__(self, restserver_url):
- self.config = ''
- self.patch = ''
+ def __init__(self, restserver_url, session_uuid=None):
+ self.config_fullpath = ''
+ self.patch_fullpath = ''
self.restserver_url = restserver_url
self.kernel_version = None
- self.session_uuid = id_generate_uuid()
+ if session_uuid:
+ self.session_uuid = session_uuid
+ else:
+ self.session_uuid = id_generate_uuid()
print('This session uuid: ' + str(self.session_uuid))
self.rest_manager = restful.ManaGer(self.restserver_url, self.kernel_version, self.session_uuid)
- def set_config(self, config_path):
- self.config = config_path
+ def set_config(self, config_fullpath):
+ self.config_fullpath = config_fullpath
- def set_patch(self, patch_path):
- self.patch = patch_path
+ def set_patch(self, patch_fullpath):
+ self.patch_fullpath = patch_fullpath
def send_files(self):
# check the configuration file
- path, file = (os.path.split(self.config))
+ path, file = (os.path.split(self.config_fullpath))
f_action = FileAction(path, file)
- if re.findall("[.]gz\Z", self.config):
+ if re.findall("[.]gz\Z", self.config_fullpath):
print('gz extension')
path, file = f_action.ungz()
# if the file is .gz the configuration path is the tmp folder uncompressed config file
- self.config = os.path.join(path,file)
+ self.config_fullpath = os.path.join(path, file)
# Get kernel version from the configuration file header
- self.kernel_version = f_action.config_kernel_version(self.config)
+ self.kernel_version = f_action.config_kernel_version(self.config_fullpath)
self.rest_manager.set_kernel_version(self.kernel_version)
print('debug: kernel version = ' + self.rest_manager.get_kernel_version())
- path, patch_file = (os.path.split(self.patch))
+ path, patch_filename = (os.path.split(self.patch_fullpath))
# send uncompressed config and patch files
- replay = self.rest_manager.send_file(self.config, self.patch, file, patch_file, '/elivepatch/api/v1.0/get_files')
+ replay = self.rest_manager.send_file(self.config_fullpath, self.patch_fullpath, file, patch_filename, '/elivepatch/api/v1.0/get_files')
def build_livepatch(self):
self.rest_manager.build_livepatch()
diff --git a/elivepatch_server/resources/dispatcher.py b/elivepatch_server/resources/dispatcher.py
index e55595b..9e5392c 100644
--- a/elivepatch_server/resources/dispatcher.py
+++ b/elivepatch_server/resources/dispatcher.py
@@ -5,7 +5,7 @@
# Distributed under the terms of the GNU General Public License v2 or later
-import uuid
+import re
import os
import werkzeug
@@ -29,18 +29,22 @@ packs = {
}
-def id_generate():
- UUID = str(uuid.uuid4())
- return UUID
-
-
def check_uuid(uuid):
+ """
+ Check uuid is in the correct format
+ :param uuid:
+ :return:
+ """
if not uuid:
- print('Generating new uuid')
- return id_generate()
+ print('uuid is missing')
else:
- print('UUID: ' + str(uuid))
- return uuid
+ # check uuid format
+ prog = re.compile('^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$')
+ result = prog.match(uuid)
+ if result:
+ print('UUID: ' + str(uuid))
+ return uuid
+ print('uuid format is not correct')
def get_uuid_dir(uuid):
@@ -114,7 +118,7 @@ class SendLivePatch(Resource):
def get(self):
args = self.reqparse.parse_args()
print("get livepatch: " + str(args))
- # check if is a new user
+ # check if is a valid UUID request
args['UUID'] = check_uuid(args['UUID'])
uuid_dir = get_uuid_dir(args['UUID'])
patch_name = lpatch.get_patch_filename()
@@ -210,6 +214,3 @@ class GetID(Resource):
def post(self):
args = self.reqparse.parse_args()
print("get ID: " + str(args))
-
-
-