-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpaths.py
125 lines (90 loc) · 3.47 KB
/
paths.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
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',
)
_compliance_summary_path = os.path.join(_own_dir, 'compliance_summary')
artefact_metadata_cfg = os.path.join(_compliance_summary_path, 'artefact_metadata_cfg.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')
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 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,
)