From 35135f3109059d5de364100ecd5aaab46fe87372 Mon Sep 17 00:00:00 2001 From: liyl_kl Date: Wed, 6 Mar 2024 14:08:53 +0800 Subject: [PATCH] Added password authentication for access to the server --- send.py | 13 +++++++++++-- src/kytuning/dependency.py | 27 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/send.py b/send.py index 23aefce..f7bbbab 100644 --- a/send.py +++ b/send.py @@ -4,6 +4,7 @@ import requests project_name="麒麟自测1" user_name = "李四" +password = "" if len(sys.argv) < 2: print("请追加all_json_file文件路径") @@ -14,13 +15,20 @@ if len(sys.argv) < 2: json_file=sys.argv[1] +url = 'http://192.28.20.200/kytuning/api-token-auth/' + +response = requests.post(url,data={'username':username,'password':password}) +if response.status_code != 200: + print("请确认账号密码正确!") + exit(0) +token = 'Bearer ' + response.json()['token'] # 读取 JSON 文件 with open(json_file, 'r') as f: json_data = f.read() # 将 JSON 字符串解析为 Python 对象 data = json.loads(json_data) # 向 Python 对象中添加新的键值对 - data['user_name'] = user_name + data['user_name'] = username data['project_name'] = project_name # 将 Python 对象编码为新的 JSON 字符串 new_json_data = json.dumps(data) @@ -29,7 +37,8 @@ with open(json_file, 'r') as f: headers = { 'User-Agent': 'curl/7.58.0', 'Accept': '*/*', - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + 'Authorization': token } response = requests.post(url, headers=headers, data=new_json_data) diff --git a/src/kytuning/dependency.py b/src/kytuning/dependency.py index a72e3f8..5652f86 100644 --- a/src/kytuning/dependency.py +++ b/src/kytuning/dependency.py @@ -45,6 +45,11 @@ class DependencyManager(object): def install_once(self, rpm=None): + """ + 安装软件 + :param rpm: + :return: + """ if rpm == None: return False @@ -54,6 +59,10 @@ class DependencyManager(object): def install(self) -> list: + """ + 安装软件的列表 + :return: + """ for rpm in self.need_install: result = self.install_once(rpm) if result == 0: @@ -70,6 +79,11 @@ class DependencyManager(object): def uninstall_once(self, rpm): + """ + 卸载软件 + :param rpm: + :return: + """ if rpm == None: return False @@ -79,11 +93,19 @@ class DependencyManager(object): def uninstall_norecord(self): + """ + 卸载已经安装完成的软件 + :return: + """ for rpm in self.succ_install[::-1]: result = self.uninstall_once(rpm) def uninstall(self) : + """ + 卸载软件列表 + :return: + """ for rpm in self.succ_install[::-1]: result = self.uninstall_once(rpm) if result == 0: @@ -98,6 +120,11 @@ class DependencyManager(object): def check_install(self, rpm): + """ + 检测软件是否安装 + :param rpm: + :return: + """ cmd = "rpm -qa --queryformat '%{name}' " + rpm result = ExecCmd(command = cmd, env = self.env).run() -- Gitee