-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfig.py
132 lines (98 loc) · 5.08 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import os
BASE_CORE_BRANCH_NAME = None
HEAD_CORE_BRANCH_NAME = None
BASE_RULE_BRANCH_NAME = None
HEAD_RULE_BRANCH_NAME = None
BASE_CORE_BRANCH_KEY = None
HEAD_CORE_BRANCH_KEY = None
BASE_SHEET_BRANCH_NAME = None
HEAD_SHEET_BRANCH_NAME = None
BASE_PRIVADO_CORE_URL = None
HEAD_PRIVADO_CORE_URL = None
BASE_PRIVADO_CORE_OWNER = None
HEAD_PRIVADO_CORE_OWNER = None
BASE_PRIVADO_RULE_URL = None
HEAD_PRIVADO_RULE_URL = None
BASE_PRIVADO_RULE_OWNER = None
HEAD_PRIVADO_RULE_OWNER = None
SLACK_SUMMARY_FILE_NAME = "slack_summary.txt"
OUTPUT_FILE_NAME = "output.xlsx"
PRIVADO_CORE_URL = "https://github.com/Privado-Inc/privado-core-enterprise"
PRIVADO_RULE_URL = "https://github.com/Privado-Inc/privado"
PRIVADO_JOERN_URL = "https://github.com/Privado-Inc/joern"
def get_privado_core_url(github_token):
return f"https://{os.getenv('CORE_AT')}@github.com/Privado-Inc/privado-core-enterprise.git"
def init(args):
global BASE_CORE_BRANCH_NAME, HEAD_CORE_BRANCH_NAME, BASE_RULE_BRANCH_NAME, HEAD_RULE_BRANCH_NAME
if args.use_rule_compare:
core_branch_names = get_core_branch(args.base, args.head, args.rules_branch_base,
args.rules_branch_head)
BASE_CORE_BRANCH_NAME = core_branch_names[0]
HEAD_CORE_BRANCH_NAME = core_branch_names[1]
else:
BASE_CORE_BRANCH_NAME = args.base
HEAD_CORE_BRANCH_NAME = args.head
rule_branch_name = get_rules_branch(BASE_CORE_BRANCH_NAME, HEAD_CORE_BRANCH_NAME, args.rules_branch_base,
args.rules_branch_head)
BASE_RULE_BRANCH_NAME = rule_branch_name[0]
HEAD_RULE_BRANCH_NAME = rule_branch_name[1]
resolve_privado_core_repo(args.token)
resolve_privado_rule_repo(args.base_rule_repo, args.head_rule_repo)
resolve_core_branch_key_name(BASE_CORE_BRANCH_NAME, HEAD_CORE_BRANCH_NAME, BASE_RULE_BRANCH_NAME,
HEAD_RULE_BRANCH_NAME, args.use_rule_compare, BASE_PRIVADO_CORE_OWNER,
HEAD_PRIVADO_CORE_OWNER, BASE_PRIVADO_RULE_OWNER, HEAD_PRIVADO_RULE_OWNER)
def resolve_core_branch_key_name(core_base_branch_name, core_head_branch_name, rules_base_branch_name,
rules_head_branch_name, rule_compare, base_core_owner, head_core_owner,
base_rule_owner, head_rule_owner):
global BASE_CORE_BRANCH_KEY, HEAD_CORE_BRANCH_KEY, BASE_SHEET_BRANCH_NAME, HEAD_SHEET_BRANCH_NAME
BASE_CORE_BRANCH_KEY = f'{base_core_owner}-{core_base_branch_name}@{base_rule_owner}-{rules_base_branch_name}'
HEAD_CORE_BRANCH_KEY = f'{head_core_owner}-{core_head_branch_name}@{head_rule_owner}-{rules_head_branch_name}'
if rule_compare:
BASE_SHEET_BRANCH_NAME = f'{base_rule_owner}-{rules_base_branch_name}'
HEAD_SHEET_BRANCH_NAME = f'{head_rule_owner}-{rules_head_branch_name}'
else:
BASE_SHEET_BRANCH_NAME = f'{base_core_owner}-{core_base_branch_name}'
HEAD_SHEET_BRANCH_NAME = f'{head_core_owner}-{core_head_branch_name}'
def get_core_branch(base_branch, head_branch, rules_branch_base, rules_branch_head):
if base_branch is None and head_branch is None:
if rules_branch_base == 'main' and rules_branch_head == 'dev':
return ['main', 'main']
else:
return ['dev', 'dev']
else:
return [base_branch, head_branch]
def get_rules_branch(base_branch, head_branch, rules_branch_base, rules_branch_head):
if rules_branch_base is None and rules_branch_head is None:
if base_branch == 'main':
return ['main', 'dev']
elif head_branch == 'main':
return ['dev', 'main']
return ['dev', 'dev']
else:
return [rules_branch_base, rules_branch_head]
def init_file():
global BASE_CORE_BRANCH_NAME, HEAD_CORE_BRANCH_NAME, BASE_CORE_BRANCH_KEY, HEAD_CORE_BRANCH_KEY, \
BASE_SHEET_BRANCH_NAME, HEAD_SHEET_BRANCH_NAME
BASE_CORE_BRANCH_NAME = BASE_CORE_BRANCH_KEY = BASE_SHEET_BRANCH_NAME = 'first'
HEAD_CORE_BRANCH_NAME = HEAD_CORE_BRANCH_KEY = HEAD_SHEET_BRANCH_NAME = 'second'
def resolve_privado_core_repo(github_token):
global BASE_PRIVADO_CORE_OWNER, HEAD_PRIVADO_CORE_OWNER, BASE_PRIVADO_CORE_URL, HEAD_PRIVADO_CORE_URL
BASE_PRIVADO_CORE_URL = get_privado_core_url(github_token)
HEAD_PRIVADO_CORE_URL = get_privado_core_url(github_token)
BASE_PRIVADO_CORE_OWNER = 'Privado-Inc'
HEAD_PRIVADO_CORE_OWNER = 'Privado-Inc'
def resolve_privado_rule_repo(base_repo, head_repo):
global BASE_PRIVADO_RULE_OWNER, HEAD_PRIVADO_RULE_OWNER, BASE_PRIVADO_RULE_URL, HEAD_PRIVADO_RULE_URL
if base_repo is None or head_repo is None:
BASE_PRIVADO_RULE_URL = PRIVADO_RULE_URL
HEAD_PRIVADO_RULE_URL = PRIVADO_RULE_URL
BASE_PRIVADO_RULE_OWNER = 'Privado-Inc'
HEAD_PRIVADO_RULE_OWNER = 'Privado-Inc'
else:
BASE_PRIVADO_RULE_URL = base_repo
HEAD_PRIVADO_RULE_URL = head_repo
BASE_PRIVADO_RULE_OWNER = get_repo_owner(base_repo)
HEAD_PRIVADO_RULE_OWNER = get_repo_owner(head_repo)
def get_repo_owner(url):
parts = url.split('/')
return parts[-2]