c2cciutils 1.8.0.dev64__py3-none-any.whl → 1.8.0.dev68__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of c2cciutils might be problematic. Click here for more details.
- c2cciutils/__init__.py +1 -194
- c2cciutils/applications-versions.yaml +0 -1
- c2cciutils/configuration.py +1 -598
- c2cciutils/schema.json +2 -317
- {c2cciutils-1.8.0.dev64.dist-info → c2cciutils-1.8.0.dev68.dist-info}/METADATA +1 -219
- c2cciutils-1.8.0.dev68.dist-info/RECORD +25 -0
- c2cciutils-1.8.0.dev68.dist-info/entry_points.txt +9 -0
- c2cciutils/lib/docker.py +0 -141
- c2cciutils/lib/oidc.py +0 -188
- c2cciutils/package-lock.json +0 -370
- c2cciutils/package.json +0 -9
- c2cciutils/publish.py +0 -451
- c2cciutils/schema-applications.json +0 -50
- c2cciutils/scripts/clean.py +0 -103
- c2cciutils/scripts/docker_versions_gen.py +0 -33
- c2cciutils/scripts/pin_pipenv.py +0 -54
- c2cciutils/scripts/publish.py +0 -477
- c2cciutils/scripts/trigger_image_update.py +0 -84
- c2cciutils/scripts/version.py +0 -245
- c2cciutils-1.8.0.dev64.dist-info/RECORD +0 -37
- c2cciutils-1.8.0.dev64.dist-info/entry_points.txt +0 -18
- {c2cciutils-1.8.0.dev64.dist-info → c2cciutils-1.8.0.dev68.dist-info}/LICENSE +0 -0
- {c2cciutils-1.8.0.dev64.dist-info → c2cciutils-1.8.0.dev68.dist-info}/WHEEL +0 -0
c2cciutils/__init__.py
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"""c2cciutils shared utils function."""
|
|
2
2
|
|
|
3
|
-
import glob
|
|
4
3
|
import json
|
|
5
4
|
import os.path
|
|
6
5
|
import re
|
|
7
6
|
import subprocess # nosec
|
|
8
7
|
import sys
|
|
9
|
-
from
|
|
10
|
-
from typing import Any, Optional, TypedDict, cast
|
|
8
|
+
from typing import Any, Optional, cast
|
|
11
9
|
|
|
12
10
|
import requests
|
|
13
11
|
import ruamel.yaml
|
|
@@ -33,26 +31,6 @@ def get_repository() -> str:
|
|
|
33
31
|
return "camptocamp/project"
|
|
34
32
|
|
|
35
33
|
|
|
36
|
-
def merge(default_config: Any, config: Any) -> Any:
|
|
37
|
-
"""
|
|
38
|
-
Deep merge the dictionaries (on dictionaries only, not on arrays).
|
|
39
|
-
|
|
40
|
-
Arguments:
|
|
41
|
-
default_config: The default config that will be applied
|
|
42
|
-
config: The base config, will be modified
|
|
43
|
-
|
|
44
|
-
"""
|
|
45
|
-
if not isinstance(default_config, dict) or not isinstance(config, dict):
|
|
46
|
-
return config
|
|
47
|
-
|
|
48
|
-
for key in default_config:
|
|
49
|
-
if key not in config:
|
|
50
|
-
config[key] = default_config[key]
|
|
51
|
-
else:
|
|
52
|
-
merge(default_config[key], config[key])
|
|
53
|
-
return config
|
|
54
|
-
|
|
55
|
-
|
|
56
34
|
def get_master_branch(repo: list[str]) -> tuple[str, bool]:
|
|
57
35
|
"""Get the name of the master branch."""
|
|
58
36
|
master_branch = "master"
|
|
@@ -77,52 +55,6 @@ def get_config() -> c2cciutils.configuration.Configuration:
|
|
|
77
55
|
yaml_ = ruamel.yaml.YAML()
|
|
78
56
|
config = yaml_.load(open_file)
|
|
79
57
|
|
|
80
|
-
repository = get_repository()
|
|
81
|
-
repo = repository.split("/")
|
|
82
|
-
master_branch, _ = get_master_branch(repo)
|
|
83
|
-
|
|
84
|
-
merge(
|
|
85
|
-
{
|
|
86
|
-
"version": {
|
|
87
|
-
"tag_to_version_re": [
|
|
88
|
-
{"from": r"([0-9]+.[0-9]+.[0-9]+)", "to": r"\1"},
|
|
89
|
-
],
|
|
90
|
-
"branch_to_version_re": [
|
|
91
|
-
{"from": r"([0-9]+.[0-9]+)", "to": r"\1"},
|
|
92
|
-
{"from": master_branch, "to": master_branch},
|
|
93
|
-
],
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
config,
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
has_docker_files = bool(
|
|
100
|
-
subprocess.run(
|
|
101
|
-
["git", "ls-files", "*/Dockerfile*", "Dockerfile*"], stdout=subprocess.PIPE, check=True
|
|
102
|
-
).stdout
|
|
103
|
-
)
|
|
104
|
-
has_python_package = bool(
|
|
105
|
-
subprocess.run(
|
|
106
|
-
["git", "ls-files", "setup.py", "*/setup.py"], stdout=subprocess.PIPE, check=True
|
|
107
|
-
).stdout
|
|
108
|
-
) or bool(
|
|
109
|
-
subprocess.run(
|
|
110
|
-
["git", "ls-files", "pyproject.toml", "*/pyproject.toml"], stdout=subprocess.PIPE, check=True
|
|
111
|
-
).stdout
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
publish_config = merge(c2cciutils.configuration.PUBLISH_DEFAULT, {})
|
|
115
|
-
publish_config["pypi"]["packages"] = [{"path": "."}] if has_python_package else []
|
|
116
|
-
publish_config["docker"]["images"] = [{"name": get_repository()}] if has_docker_files else []
|
|
117
|
-
publish_config["helm"]["folders"] = [
|
|
118
|
-
os.path.dirname(f) for f in glob.glob("./**/Chart.yaml", recursive=True)
|
|
119
|
-
]
|
|
120
|
-
|
|
121
|
-
default_config = {
|
|
122
|
-
"publish": publish_config,
|
|
123
|
-
}
|
|
124
|
-
merge(default_config, config)
|
|
125
|
-
|
|
126
58
|
return config
|
|
127
59
|
|
|
128
60
|
|
|
@@ -170,102 +102,6 @@ def error(
|
|
|
170
102
|
print(f"[{error_type}] {result}")
|
|
171
103
|
|
|
172
104
|
|
|
173
|
-
VersionTransform = TypedDict(
|
|
174
|
-
"VersionTransform",
|
|
175
|
-
{
|
|
176
|
-
# The from regular expression
|
|
177
|
-
"from": Pattern[str],
|
|
178
|
-
# The expand regular expression: https://docs.python.org/3/library/re.html#re.Match.expand
|
|
179
|
-
"to": str,
|
|
180
|
-
},
|
|
181
|
-
total=False,
|
|
182
|
-
)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
def compile_re(config: c2cciutils.configuration.VersionTransform, prefix: str = "") -> list[VersionTransform]:
|
|
186
|
-
"""
|
|
187
|
-
Compile the from as a regular expression of a dictionary of the config list.
|
|
188
|
-
|
|
189
|
-
to be used with convert and match
|
|
190
|
-
|
|
191
|
-
Arguments:
|
|
192
|
-
config: The transform config
|
|
193
|
-
prefix: The version prefix
|
|
194
|
-
|
|
195
|
-
Return the compiled transform config.
|
|
196
|
-
|
|
197
|
-
"""
|
|
198
|
-
result = []
|
|
199
|
-
for conf in config:
|
|
200
|
-
new_conf = cast(VersionTransform, dict(conf))
|
|
201
|
-
|
|
202
|
-
from_re = conf.get("from", r"(.*)")
|
|
203
|
-
if from_re[0] == "^":
|
|
204
|
-
from_re = from_re[1:]
|
|
205
|
-
if from_re[-1] != "$":
|
|
206
|
-
from_re += "$"
|
|
207
|
-
from_re = f"^{re.escape(prefix)}{from_re}"
|
|
208
|
-
|
|
209
|
-
new_conf["from"] = re.compile(from_re)
|
|
210
|
-
result.append(new_conf)
|
|
211
|
-
return result
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
def match(
|
|
215
|
-
value: str, config: list[VersionTransform]
|
|
216
|
-
) -> tuple[Optional[Match[str]], Optional[VersionTransform], str]:
|
|
217
|
-
"""
|
|
218
|
-
Get the matched version.
|
|
219
|
-
|
|
220
|
-
Arguments:
|
|
221
|
-
value: That we want to match with
|
|
222
|
-
config: The result of `compile`
|
|
223
|
-
|
|
224
|
-
Returns the re match object, the matched config and the value as a tuple
|
|
225
|
-
On no match it returns None, value
|
|
226
|
-
|
|
227
|
-
"""
|
|
228
|
-
for conf in config:
|
|
229
|
-
matched = conf["from"].match(value)
|
|
230
|
-
if matched is not None:
|
|
231
|
-
return matched, conf, value
|
|
232
|
-
return None, None, value
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
def does_match(value: str, config: list[VersionTransform]) -> bool:
|
|
236
|
-
"""
|
|
237
|
-
Check if the version match with the config patterns.
|
|
238
|
-
|
|
239
|
-
Arguments:
|
|
240
|
-
value: That we want to match with
|
|
241
|
-
config: The result of `compile`
|
|
242
|
-
|
|
243
|
-
Returns True it it does match else False
|
|
244
|
-
|
|
245
|
-
"""
|
|
246
|
-
matched, _, _ = match(value, config)
|
|
247
|
-
return matched is not None
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
def get_value(matched: Optional[Match[str]], config: Optional[VersionTransform], value: str) -> str:
|
|
251
|
-
"""
|
|
252
|
-
Get the final value.
|
|
253
|
-
|
|
254
|
-
`match`, `config` and `value` are the result of `match`.
|
|
255
|
-
|
|
256
|
-
The `config` should have a `to` key with an expand template.
|
|
257
|
-
|
|
258
|
-
Arguments:
|
|
259
|
-
matched: The matched object to a regular expression
|
|
260
|
-
config: The result of `compile`
|
|
261
|
-
value: The default value on returned no match
|
|
262
|
-
|
|
263
|
-
Return the value
|
|
264
|
-
|
|
265
|
-
"""
|
|
266
|
-
return matched.expand(config.get("to", r"\1")) if matched is not None and config is not None else value
|
|
267
|
-
|
|
268
|
-
|
|
269
105
|
def print_versions(config: c2cciutils.configuration.PrintVersions) -> bool:
|
|
270
106
|
"""
|
|
271
107
|
Print some tools version.
|
|
@@ -321,18 +157,6 @@ def gopass(key: str, default: Optional[str] = None) -> Optional[str]:
|
|
|
321
157
|
raise
|
|
322
158
|
|
|
323
159
|
|
|
324
|
-
def gopass_put(secret: str, key: str) -> None:
|
|
325
|
-
"""
|
|
326
|
-
Put an entry in gopass.
|
|
327
|
-
|
|
328
|
-
Arguments:
|
|
329
|
-
secret: The secret value
|
|
330
|
-
key: The key
|
|
331
|
-
|
|
332
|
-
"""
|
|
333
|
-
subprocess.check_output(["gopass", "insert", "--force", key], input=secret.encode())
|
|
334
|
-
|
|
335
|
-
|
|
336
160
|
def add_authorization_header(headers: dict[str, str]) -> dict[str, str]:
|
|
337
161
|
"""
|
|
338
162
|
Add the Authorization header needed to be authenticated on GitHub.
|
|
@@ -411,20 +235,3 @@ def graphql(query_file: str, variables: dict[str, Any], default: Any = None) ->
|
|
|
411
235
|
if "data" not in json_response:
|
|
412
236
|
raise RuntimeError(f"GraphQL no data: {json.dumps(json_response, indent=2)}")
|
|
413
237
|
return cast(dict[str, Any], json_response["data"])
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
def snyk_exec() -> tuple[str, dict[str, str]]:
|
|
417
|
-
"""Get the Snyk cli executable path."""
|
|
418
|
-
if not os.path.exists(os.path.join(os.path.dirname(__file__), "node_modules")):
|
|
419
|
-
subprocess.run(["npm", "install"], cwd=os.path.dirname(__file__), check=True) # nosec
|
|
420
|
-
|
|
421
|
-
env = {**os.environ}
|
|
422
|
-
env["FORCE_COLOR"] = "true"
|
|
423
|
-
if "SNYK_TOKEN" not in env:
|
|
424
|
-
token = gopass("gs/ci/snyk/token")
|
|
425
|
-
if token is not None:
|
|
426
|
-
env["SNYK_TOKEN"] = token
|
|
427
|
-
if "SNYK_ORG" in env:
|
|
428
|
-
subprocess.run(["snyk", "config", "set", f"org={env['SNYK_ORG']}"], check=True, env=env)
|
|
429
|
-
|
|
430
|
-
return os.path.join(os.path.dirname(os.path.abspath(__file__)), "node_modules/snyk/bin/snyk"), env
|