Commit 30dae187 authored by zhaokai's avatar zhaokai

apis 模块

parent 9f4ade38
File added
File added
__pycache__/
*.cache
\ No newline at end of file
#!/usr/bin/env python3
#!/usr/bin/env python3
import requests,json
from common.token import getToken
# 拉取git提交节点
def getGits(projectid, env):
cookie = getToken()
url = f'https://gw.qimai.shop/api/jenkins/jenkinsjob/git/?projectid={projectid}&env={env}'
payload={}
headers = {
'authority': 'gw.qimai.shop',
'sec-ch-ua': '"Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99"',
'accept': 'application/json, text/plain, */*',
'x-xsrftoken': 'undefined',
'sec-ch-ua-mobile': '?0',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36',
'sec-ch-ua-platform': '"macOS"',
'origin': 'https://opms.qimai.shop',
'sec-fetch-site': 'same-site',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://opms.qimai.shop/',
'accept-language': 'zh-CN,zh;q=0.9',
'cookie': cookie
}
response = requests.request("GET", url, headers=headers, data=payload)
# print(response.text)
rst = json.loads(response.text)
rst_data = rst['data']
return rst_data
\ No newline at end of file
#!/usr/bin/env python3
import requests,json
from common.token import getToken
# 拉取环境
def getEnvs():
cookie = getToken()
url = "https://gw.qimai.shop/api/jenkins/jenkinsjob/getenv/?projectid=47"
payload={}
headers = {
'authority': 'gw.qimai.shop',
'sec-ch-ua': '"Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99"',
'accept': 'application/json, text/plain, */*',
'x-xsrftoken': 'undefined',
'sec-ch-ua-mobile': '?0',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36',
'sec-ch-ua-platform': '"macOS"',
'origin': 'https://opms.qimai.shop',
'sec-fetch-site': 'same-site',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://opms.qimai.shop/',
'accept-language': 'zh-CN,zh;q=0.9',
'cookie': cookie
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
# 拉取项目列表
def getProjects():
cookie = getToken()
url = "https://gw.qimai.shop/api/jenkins/jenkinsjob/projects/?page_size=1000"
payload={}
headers = {
'authority': 'gw.qimai.shop',
'sec-ch-ua': '"Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99"',
'accept': 'application/json, text/plain, */*',
'x-xsrftoken': 'undefined',
'sec-ch-ua-mobile': '?0',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36',
'sec-ch-ua-platform': '"macOS"',
'origin': 'https://opms.qimai.shop',
'sec-fetch-site': 'same-site',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://opms.qimai.shop/',
'accept-language': 'zh-CN,zh;q=0.9',
'cookie': cookie
}
response = requests.request("GET", url, headers=headers, data=payload)
rst = json.loads(response.text)
rst_results = rst['results']
return rst_results
\ No newline at end of file
#!/usr/bin/env python3
import requests
import json
from filecache import filecache
# opms 登录
# 登录token缓存8小时
@filecache(8 * 3600)
def login(username, password):
print("重新登录")
url = "https://gw.qimai.shop/api/accounts/login/"
# 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"',
'accept': 'application/json, text/plain, */*',
'x-xsrftoken': 'undefined',
'sec-ch-ua-mobile': '?0',
'content-type': 'application/json;charset=UTF-8',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36',
'sec-ch-ua-platform': '"macOS"',
'origin': 'https://opms.qimai.shop',
'sec-fetch-site': 'same-site',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://opms.qimai.shop/',
'accept-language': 'zh-CN,zh;q=0.9',
'cookie': 'nickname=2|1:0|10:1637042878|8:nickname|8:6LW15Yev|28c15cdbb78ddb15a2bc1909ffe248c87b699029eae4653ac4aafc0f858015d3; username="2|1:0|10:1637042878|8:username|4:ems=|883823b05173926570e7a03603cfe6a2debfd55b8b265aad28246548f0753dd2"; user_id="2|1:0|10:1637042878|7:user_id|4:NDU=|fdcd39aeeea0f1a7a28da3acd0fbd950909a61782ca5ece5730a19380f995c47"; email="2|1:0|10:1637042878|5:email|16:emtAcW1haS5jbg==|8755872e364b8fecf2d4687001d642957c7cbce73a555e5d34747bc9cc8fe307"; qm_seller_token=RhQk8S49escwDFv/8HxKGi0BNFl6fCJ0NFbaAxtpaPTi1f4Cbf0vcSTBEkRrmpSA; qm_account_token=lHyat65sBt-Q0E3TN_h9Lje-p8WKN6qWx7RQ_HZ__F5vd1y_fwH_E_CEseq2cCRm; csrf_key=Y5mrjjTgXzgnAxfLdE4vsF; user_id="2|1:0|10:1637129080|7:user_id|4:NDU=|dff079050c035a186a16faddfd23465edea5622699e7df0bd89c9330c8ed4524"; nickname=2|1:0|10:1637129080|8:nickname|8:6LW15Yev|32bffc62ceee8d0f5fb1839fb22b9d70c49f60b277e063ae250612a42d5bf421; username="2|1:0|10:1637129080|8:username|4:ems=|d58c52a24b960f48597d6658fff45667a6cd2a0b63a750f6ba82439c565dafa0"; email="2|1:0|10:1637129080|5:email|16:emtAcW1haS5jbg==|4519e0388c9f9b8264650ab8a8e2eb219c0b3fc829a873eea31f8ccd4ed57109"; auth_key=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MzcyOTMyNjAsIm5iZiI6MTYzNzIwNjg0MCwiaWF0IjoxNjM3MjA2ODUwLCJpc3MiOiJhdXRoOiBzcyIsInN1YiI6Im15IHRva2VuIiwiaWQiOiIxNTYxODcxODA2MCIsImRhdGEiOnsidXNlcl9pZCI6IjQ1IiwidXNlcm5hbWUiOiJ6ayIsIm5pY2tuYW1lIjoiXHU4ZDc1XHU1MWVmIiwiZW1haWwiOiJ6a0BxbWFpLmNuIiwiaXNfc3VwZXJ1c2VyIjpmYWxzZX19.3uH5zBj1ftxVvLdnE5QU7wRMlAskB4ZW_CBdM-CFd8A; nickname=2|1:0|10:1637206850|8:nickname|8:6LW15Yev|993301ac0754ca2a3a1282541551ea6da2f796d3304975a2336ae3694209bccc; username="2|1:0|10:1637206850|8:username|4:ems=|6a2d566ee5c922c0ee9e3423d8a2d6c0cbef37982ce4dfa8842ac8acac18a155"; user_id="2|1:0|10:1637206850|7:user_id|4:NDU=|66767a733ea13ec97281ec7c88175df1353485cd55066af740119434d631e58f"; email="2|1:0|10:1637206850|5:email|16:emtAcW1haS5jbg==|51efabda93dd7e238eeb833e6e2cde21176429aede9c0a76f0abdd460da33784"; codo_nickname=6LW15Yev'
}
response = requests.request("POST", url, headers=headers, data=payload)
rst = json.loads(response.text)
rst_auth_key = rst['auth_key'];
return rst_auth_key
\ No newline at end of file
#!/usr/bin/env python3
import requests,json
from common.token import getToken
# 执行部署任务
def tasksPatch(taskid):
cookie = getToken()
url = "https://gw.qimai.shop/api/jenkins/jenkinsjob/tasks/"
# payload="{\"status\":3,\"taskid\":54485}"
payload=f'{{"status":3,"taskid":{taskid}}}'
headers = {
'authority': 'gw.qimai.shop',
'sec-ch-ua': '"Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99"',
'accept': 'application/json, text/plain, */*',
'x-xsrftoken': 'undefined',
'sec-ch-ua-mobile': '?0',
'content-type': 'application/json;charset=UTF-8',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36',
'sec-ch-ua-platform': '"macOS"',
'origin': 'https://opms.qimai.shop',
'sec-fetch-site': 'same-site',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://opms.qimai.shop/',
'accept-language': 'zh-CN,zh;q=0.9',
'cookie': cookie
}
response = requests.request("PATCH", url, headers=headers, data=payload)
print("任务开始执行...")
\ No newline at end of file
#!/usr/bin/env python3
import requests,json
from common.token import getToken
def taskstatus(taskid):
cookie = getToken()
url = f'https://gw.qimai.shop/api/jenkins/jenkinsjob/taskstatus/?taskid={taskid}'
payload={}
headers = {
'authority': 'gw.qimai.shop',
'sec-ch-ua': '"Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99"',
'accept': 'application/json, text/plain, */*',
'x-xsrftoken': 'undefined',
'sec-ch-ua-mobile': '?0',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36',
'sec-ch-ua-platform': '"macOS"',
'origin': 'https://opms.qimai.shop',
'sec-fetch-site': 'same-site',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://opms.qimai.shop/',
'accept-language': 'zh-CN,zh;q=0.9',
'cookie': cookie
}
response = requests.request("GET", url, headers=headers, data=payload)
# print(response.text)
rst = json.loads(response.text)
# status=3 执行中
# status=4 执行成功
return rst['status']
\ No newline at end of file
#!/usr/bin/env python3
import requests,json
from common.token import getToken
def tasks(projectid, env, commitid, info):
cookie = getToken()
url = "https://gw.qimai.shop/api/jenkins/jenkinsjob/tasks/"
# payload="{\"gray\":false,\"eta\":\"\",\"pname\":47,\"env\":\"test\",\"ref\":\"test\",\"info\":\"test 部署, 桌码迁移\",\"commitid\":\"e974fb255fd38020367d0a6ed54949d121ecf548\"}"
payload=f'{{"gray":false,"eta":"","pname":"{projectid}","env":"{env}","ref":"{env}","info":"{info}","commitid":"{commitid}"}}'
payload=payload.encode("utf-8").decode("latin1")
headers = {
'authority': 'gw.qimai.shop',
'sec-ch-ua': '"Google Chrome";v="95", "Chromium";v="95", ";Not A Brand";v="99"',
'accept': 'application/json, text/plain, */*',
'x-xsrftoken': 'undefined',
'sec-ch-ua-mobile': '?0',
'content-type': 'application/json;charset=UTF-8',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36',
'sec-ch-ua-platform': '"macOS"',
'origin': 'https://opms.qimai.shop',
'sec-fetch-site': 'same-site',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://opms.qimai.shop/',
'accept-language': 'zh-CN,zh;q=0.9',
'cookie': cookie
}
response = requests.request("POST", url, headers=headers, data=payload)
# print(response.text)
rst = json.loads(response.text)
print("任务生成成功: ", rst['id'])
return rst['id']
\ No newline at end of file
#!/usr/bin/env python3
#!/usr/bin/env python3
import os
import yaml
# from filecache import filecache
# 登录token缓存8小时
# @filecache(8 * 3600)
def getconfig():
# 获取脚本所在目录
base_path = os.path.split(os.path.realpath(__file__))[0]
# 读取配置
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("读取配置失败")
return config
\ No newline at end of file
#!/usr/bin/env python3
from common.config import getconfig
from apis.login_api import login
def getToken():
# 读取配置
config = getconfig()
# 全局token
cookie = f'auth_key=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MzcyOTMyNjAsIm5iZiI6MTYzNzIwNjg0MCwiaWF0IjoxNjM3MjA2ODUwLCJpc3MiOiJhdXRoOiBzcyIsInN1YiI6Im15IHRva2VuIiwiaWQiOiIxNTYxODcxODA2MCIsImRhdGEiOnsidXNlcl9pZCI6IjQ1IiwidXNlcm5hbWUiOiJ6ayIsIm5pY2tuYW1lIjoiXHU4ZDc1XHU1MWVmIiwiZW1haWwiOiJ6a0BxbWFpLmNuIiwiaXNfc3VwZXJ1c2VyIjpmYWxzZX19.3uH5zBj1ftxVvLdnE5QU7wRMlAskB4ZW_CBdM-CFd8A;'
# 登录账号
username = config['login']['username']
# 登录密码
password = config['login']['password']
# 主逻辑
auth_key = login(username, password)
# 替换全局token
cookie = f'auth_key={auth_key}'
return cookie
\ No newline at end of file
This diff is collapsed.
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