Commit aac37502 authored by zhaokai's avatar zhaokai

config.yaml

parent d7e7e3a3
config.yaml
opms.py.cache
\ No newline at end of file
login:
username: zk
password: 1qaz!QAZ
\ No newline at end of file
......@@ -4,14 +4,53 @@ import sys
import requests
import json
import time
import yaml
from filecache import filecache
# 获取命令行参数
argv = sys.argv
# 获取脚本所在目录
base_path = os.path.split(os.path.realpath(__file__))[0]
# 验证
if len(argv) == 1:
sys.exit("env环境参数未设置")
else:
env = argv[1]
if env not in ["test","beta"]:
sys.exit("env环境参数设置错误")
if len(argv) == 2:
info = env + "部署"
else:
info = argv[2]
# 读取配置
yamlPath = base_path + '/config.yaml'
with open(yamlPath, "r") as stream:
try:
config = yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc)
exit("读取配置失败")
# 全局token
cookie = f'auth_key=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MzcyOTMyNjAsIm5iZiI6MTYzNzIwNjg0MCwiaWF0IjoxNjM3MjA2ODUwLCJpc3MiOiJhdXRoOiBzcyIsInN1YiI6Im15IHRva2VuIiwiaWQiOiIxNTYxODcxODA2MCIsImRhdGEiOnsidXNlcl9pZCI6IjQ1IiwidXNlcm5hbWUiOiJ6ayIsIm5pY2tuYW1lIjoiXHU4ZDc1XHU1MWVmIiwiZW1haWwiOiJ6a0BxbWFpLmNuIiwiaXNfc3VwZXJ1c2VyIjpmYWxzZX19.3uH5zBj1ftxVvLdnE5QU7wRMlAskB4ZW_CBdM-CFd8A;'
# 登录账号
username = config['login']['username']
# 登录密码
password = config['login']['password']
# opms 登录
def login():
# 登录token缓存8小时
@filecache(8 * 3600)
def login(username, password):
print("重新登录")
url = "https://gw.qimai.shop/api/accounts/login/"
payload="{\"username\":\"zk\",\"password\":\"1qaz!QAZ\",\"dynamic\":\"\"}"
# payload="{\"username\":\"zk\",\"password\":\"123456\",\"dynamic\":\"\"}"
payload = f'{{"username":"{username}","password":"{password}","dynamic":""}}'
headers = {
'authority': 'gw.qimai.shop',
'sec-ch-ua': '"Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99"',
......@@ -32,9 +71,8 @@ def login():
response = requests.request("POST", url, headers=headers, data=payload)
rst = json.loads(response.text)
rst_auth_key = rst['auth_key'];
# 替换全局token
global cookie
cookie = f'auth_key={rst_auth_key}'
return rst_auth_key
# 拉取项目列表
......@@ -221,28 +259,22 @@ def checkCommitid(projectid, env):
# 主逻辑
login()
argv = sys.argv
auth_key = login(username, password)
exit(auth_key);
# 替换全局token
cookie = f'auth_key={auth_key}'
if len(argv) == 1:
sys.exit("env环境参数未设置")
else:
env = argv[1]
if env not in ["test","beta"]:
sys.exit("env环境参数设置错误")
if len(argv) == 2:
info = env + "部署"
else:
info = argv[2]
# 识别项目
projectid = checkProjId()
# 拉取提交节点
commitid = checkCommitid(projectid, env)
# 创建部署任务
taskid = tasks(projectid, env, commitid, info)
time.sleep(3)
# 执行部署任务
tasksPatch(taskid)
# 轮训任务状态
is_continue = 1
while is_continue == 1:
time.sleep(3)
......
Markdown is supported
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