Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
opms-command
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
赵凯
opms-command
Commits
aac37502
Commit
aac37502
authored
Nov 19, 2021
by
zhaokai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
config.yaml
parent
d7e7e3a3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
20 deletions
+57
-20
.gitignore
.gitignore
+2
-0
example.config.yaml
example.config.yaml
+3
-0
opms.py
opms.py
+52
-20
No files found.
.gitignore
0 → 100644
View file @
aac37502
config.yaml
opms.py.cache
\ No newline at end of file
example.config.yaml
0 → 100644
View file @
aac37502
login
:
username
:
zk
password
:
1qaz!QAZ
\ No newline at end of file
opms.py
View file @
aac37502
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment