-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathpaths.py
More file actions
173 lines (126 loc) · 4.88 KB
/
paths.py
File metadata and controls
173 lines (126 loc) · 4.88 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import collections.abc
import logging
import os
logger = logging.getLogger(__name__)
_own_dir = os.path.abspath(os.path.dirname(__file__))
_json_schema_path = os.path.join(_own_dir, 'schema')
token_jsonschema_path = os.path.join(_json_schema_path, 'token-payload-schema.yaml')
_responsibles_path = os.path.join(_own_dir, 'responsibles')
responsibles_username_negative_list_path = os.path.join(
_responsibles_path,
'responsibles_username_negative_list.yaml',
)
test_resources_apiserver_proxy = os.path.join(_own_dir, 'test/resources/apiserver-proxy.json')
test_resources_mcm = os.path.join(_own_dir, 'test/resources/machine-controller-manager.json')
test_resources_gardener_org_members = os.path.join(
_own_dir,
'test/resources/gardener_org_members.yaml',
)
_features_path = os.path.join(_own_dir, 'features')
swagger_path = os.path.join(_own_dir, 'swagger', 'swagger.yaml')
_odg_path = os.path.join(_own_dir, 'odg')
_secret_mgmt_path = os.path.join(_own_dir, 'secret_mgmt')
builtin_role_bindings_path = os.path.join(_secret_mgmt_path, 'builtin-role-bindings.yaml')
def features_cfg_candidates() -> collections.abc.Generator[str, None, None]:
if features_cfg_path := os.environ.get('FEATURES_CFG_PATH'):
yield features_cfg_path
yield os.path.join(_features_path, 'features_cfg.yaml')
def extensions_cfg_candidates() -> collections.abc.Generator[str, None, None]:
if extensions_cfg_path := os.environ.get('EXTENSIONS_CFG_PATH'):
yield extensions_cfg_path
yield os.path.join(_odg_path, 'extensions_cfg.yaml')
def findings_cfg_candidates() -> collections.abc.Generator[str, None, None]:
if findings_cfg_path := os.environ.get('FINDINGS_CFG_PATH'):
yield findings_cfg_path
yield os.path.join(_odg_path, 'findings_cfg.yaml')
def ocm_repo_mappings_candidates() -> collections.abc.Generator[str, None, None]:
if ocm_repo_mappings_path := os.environ.get('OCM_REPO_MAPPINGS_PATH'):
yield ocm_repo_mappings_path
yield os.path.join(_odg_path, 'ocm_repo_mappings.yaml')
def profiles_candidates() -> collections.abc.Generator[str, None, None]:
if profiles_path := os.environ.get('PROFILES_PATH'):
yield profiles_path
yield os.path.join(_odg_path, 'profiles.yaml')
def sprints_candidates() -> collections.abc.Generator[str, None, None]:
if sprints_path := os.environ.get('SPRINTS_PATH'):
yield sprints_path
yield os.path.join(_features_path, 'sprints.yaml')
def addressbook_candidates() -> collections.abc.Generator[str, None, None]:
if addressbook_path := os.environ.get('ADDRESSBOOK_PATH'):
yield addressbook_path
yield os.path.join(_features_path, 'addressbook.yaml')
def github_mappings_candidates() -> collections.abc.Generator[str, None, None]:
if github_mappings_path := os.environ.get('GITHUB_MAPPINGS_PATH'):
yield github_mappings_path
yield os.path.join(_features_path, 'github_mappings.yaml')
def find_path(
candidates: collections.abc.Iterable[str],
absent_ok: bool = False,
) -> str | None:
for candidate in candidates:
if not os.path.isfile(candidate):
logger.warning(f'not an existing file: {candidate=}')
continue
return candidate
if absent_ok:
return None
raise ValueError(f'did not find file at any of {candidates=}')
def features_cfg_path(
absent_ok: bool = False,
) -> str | None:
return find_path(
candidates=features_cfg_candidates(),
absent_ok=absent_ok,
)
def extensions_cfg_path(
absent_ok: bool = False,
) -> str | None:
return find_path(
candidates=extensions_cfg_candidates(),
absent_ok=absent_ok,
)
def findings_cfg_path(
absent_ok: bool = False,
) -> str | None:
return find_path(
candidates=findings_cfg_candidates(),
absent_ok=absent_ok,
)
def ocm_repo_mappings_path(
absent_ok: bool = False,
) -> str | None:
return find_path(
candidates=ocm_repo_mappings_candidates(),
absent_ok=absent_ok,
)
def profiles_path(
absent_ok: bool = False,
) -> str | None:
return find_path(
candidates=profiles_candidates(),
absent_ok=absent_ok,
)
def sprints_path(
path_overwrite: str | None = None,
absent_ok: bool = False,
) -> str | None:
return find_path(
candidates=[path_overwrite] if path_overwrite else sprints_candidates(),
absent_ok=absent_ok,
)
def addressbook_path(
path_overwrite: str | None = None,
absent_ok: bool = False,
) -> str | None:
return find_path(
candidates=[path_overwrite] if path_overwrite else addressbook_candidates(),
absent_ok=absent_ok,
)
def github_mappings_path(
path_overwrite: str | None = None,
absent_ok: bool = False,
) -> str | None:
return find_path(
candidates=[path_overwrite] if path_overwrite else github_mappings_candidates(),
absent_ok=absent_ok,
)