Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
config_repository
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QA
config_repository
Commits
ea251230
Commit
ea251230
authored
Nov 20, 2018
by
xuezj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支持定义规则顺序
parent
7fe54549
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
16 deletions
+18
-16
replace.py
yaml/replace.py
+4
-10
replace_config.yaml
yaml/replace_config.yaml
+14
-6
No files found.
yaml/replace.py
View file @
ea251230
...
@@ -8,22 +8,21 @@ import os.path
...
@@ -8,22 +8,21 @@ import os.path
import
re
import
re
import
copy
import
copy
import
sys
import
sys
# import requests
opApiHost
=
'http://172.30.220.22:3003'
opApiHost
=
'http://172.30.220.22:3003'
f
=
io
.
open
(
'replace_config.yaml'
,
'r'
,
encoding
=
'utf-8'
)
f
=
io
.
open
(
'replace_config.yaml'
,
'r'
,
encoding
=
'utf-8'
)
res
=
yaml
.
load
(
f
)
res
=
yaml
.
load
(
f
)
print
(
"全部配置信息:"
,
res
)
print
(
"全部配置信息:"
,
res
)
#
查看配置中是否有当前项目
#
获取当前项目的配置
env
=
os
.
environ
env
=
os
.
environ
project
=
env
.
get
(
'SYSTEM_NAME'
)
project
=
env
.
get
(
'SYSTEM_NAME'
)
distPath
=
os
.
path
.
abspath
(
project
+
'/dist'
)
distPath
=
os
.
path
.
abspath
(
project
+
'/dist'
)
config
=
res
.
get
(
project
,
res
.
get
(
'common'
))
config
=
res
.
get
(
project
,
res
.
get
(
'common'
))
config
=
sorted
(
config
.
items
(),
key
=
lambda
rule
:
(
rule
[
1
][
'order'
],
rule
[
0
]))
print
(
project
,
"的配置信息:"
,
config
)
print
(
project
,
"的配置信息:"
,
config
)
print
(
"dist路径:"
,
distPath
)
print
(
"dist路径:"
,
distPath
)
# 根据内容进行替换
namespace
=
env
.
get
(
'NAMESPACE'
)
namespace
=
env
.
get
(
'NAMESPACE'
)
print
(
'namespace:'
,
namespace
)
print
(
'namespace:'
,
namespace
)
...
@@ -46,16 +45,11 @@ findFile(distPath)
...
@@ -46,16 +45,11 @@ findFile(distPath)
for
file
in
files
:
for
file
in
files
:
for
line
in
fileinput
.
input
(
file
,
inplace
=
1
):
for
line
in
fileinput
.
input
(
file
,
inplace
=
1
):
for
item
in
config
:
for
item
in
config
:
if
not
config
[
item
]:
rule
=
copy
.
deepcopy
(
item
[
1
])
continue
rule
=
copy
.
deepcopy
(
config
[
item
])
if
rule
.
get
(
'useNamespace'
,
None
)
and
rule
[
'to'
]:
if
rule
.
get
(
'useNamespace'
,
None
)
and
rule
[
'to'
]:
rule
[
'to'
]
=
'-'
+
namespace
+
rule
[
'to'
]
rule
[
'to'
]
=
'-'
+
namespace
+
rule
[
'to'
]
if
rule
.
get
(
'useDomain'
,
None
):
if
rule
.
get
(
'useDomain'
,
None
):
# domain = requests.get(opApiHost + '/proconfig/get_host?system_name=' + project)
# domain = domain.json['data'].split('.')[0]
domain
=
sys
.
argv
[
1
]
.
split
(
'.'
)[
0
]
domain
=
sys
.
argv
[
1
]
.
split
(
'.'
)[
0
]
rule
[
'to'
]
=
'//'
+
domain
+
rule
[
'to'
]
rule
[
'to'
]
=
'//'
+
domain
+
rule
[
'to'
]
...
...
yaml/replace_config.yaml
View file @
ea251230
# reg: 匹配的正则
# reg: 匹配的正则
# to: 正则匹配后替换需要的值
# to: 正则匹配后替换需要的值
# useNamespace: 是否在替换的值前追加 '-[namespace名称]'
# useNamespace: 是否在替换的值前追加 '-[namespace名称]'
# order 默认0
rule
:
&rule
reg
:
'
'
to
:
'
'
useNamespace
:
false
order
:
0
lkbDomain
:
&lkbDomain
'
.liangkebang.com'
lkbDomain
:
&lkbDomain
'
.liangkebang.com'
# 替换xyqbapi
# 替换xyqbapi
xyqbApiRule
:
&xyqbApiRule
xyqbApiRule
:
&xyqbApiRule
<<
:
*rule
reg
:
'
(?<=\w).xyqb.com'
reg
:
'
(?<=\w).xyqb.com'
to
:
*lkbDomain
to
:
*lkbDomain
useNamespace
:
true
useNamespace
:
true
# 替换quantgroupApi
# 替换quantgroupApi
quantgroupApiRule
:
&quantgroupApiRule
quantgroupApiRule
:
&quantgroupApiRule
<<
:
*rule
reg
:
'
(?<=\w).quantgroup.cn'
reg
:
'
(?<=\w).quantgroup.cn'
to
:
*lkbDomain
to
:
*lkbDomain
useNamespace
:
true
useNamespace
:
true
# 替换cookie
# 替换cookie
xyqbCookieRule
:
&xyqbCookieRule
xyqbCookieRule
:
&xyqbCookieRule
<<
:
*rule
reg
:
'
(?<![\w]).xyqb.com'
reg
:
'
(?<![\w]).xyqb.com'
to
:
*lkbDomain
to
:
*lkbDomain
qgApiRule
:
&qgApiRule
qgApiRule
:
&qgApiRule
<<
:
*rule
reg
:
'
(?<=\w).q-gp.com'
reg
:
'
(?<=\w).q-gp.com'
to
:
*lkbDomain
to
:
*lkbDomain
useNamespace
:
true
useNamespace
:
true
qgCookieRule
:
&qgCookieRule
qgCookieRule
:
&qgCookieRule
<<
:
*rule
reg
:
'
(?<![\w]).q-gp.com'
reg
:
'
(?<![\w]).q-gp.com'
to
:
*lkbDomain
to
:
*lkbDomain
# todo: 看哪个项目需要
h5AuthRule
:
&h5AuthRule
h5AuthRule
:
&h5AuthRule
<<
:
*rule
reg
:
'
auth[-a-z]*\.[a-z]*\.[a-z]*'
reg
:
'
auth[-a-z]*\.[a-z]*\.[a-z]*'
to
:
'
operator.liangkebang.com'
to
:
'
operator.liangkebang.com'
# staticRule: &staticRule
# reg: '//static[-/0-9a-z.]*public'
# to: ''
staticRule
:
&staticRule
staticRule
:
&staticRule
<<
:
*rule
reg
:
'
//static[-/0-9a-z.]*public'
reg
:
'
//static[-/0-9a-z.]*public'
to
:
*lkbDomain
to
:
*lkbDomain
useNamespace
:
true
useNamespace
:
true
...
...
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