c2cciutils 1.7.0.dev174__py3-none-any.whl → 1.8.0.dev45__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.

Files changed (35) hide show
  1. c2cciutils/__init__.py +15 -230
  2. c2cciutils/applications-versions.yaml +3 -3
  3. c2cciutils/applications_definition.py +20 -22
  4. c2cciutils/configuration.py +83 -554
  5. c2cciutils/env.py +8 -31
  6. c2cciutils/lib/docker.py +2 -8
  7. c2cciutils/lib/oidc.py +188 -0
  8. c2cciutils/package-lock.json +115 -127
  9. c2cciutils/package.json +1 -1
  10. c2cciutils/publish.py +26 -44
  11. c2cciutils/schema.json +3 -230
  12. c2cciutils/scripts/__init__.py +1 -3
  13. c2cciutils/scripts/clean.py +4 -11
  14. c2cciutils/scripts/docker_logs.py +4 -4
  15. c2cciutils/scripts/docker_versions_gen.py +0 -1
  16. c2cciutils/scripts/download_applications.py +0 -2
  17. c2cciutils/scripts/env.py +2 -6
  18. c2cciutils/scripts/k8s/__init__.py +1 -3
  19. c2cciutils/scripts/k8s/wait.py +2 -2
  20. c2cciutils/scripts/main.py +4 -16
  21. c2cciutils/scripts/publish.py +45 -31
  22. c2cciutils/scripts/trigger_image_update.py +3 -8
  23. c2cciutils/scripts/version.py +5 -4
  24. {c2cciutils-1.7.0.dev174.dist-info → c2cciutils-1.8.0.dev45.dist-info}/LICENSE +1 -1
  25. {c2cciutils-1.7.0.dev174.dist-info → c2cciutils-1.8.0.dev45.dist-info}/METADATA +29 -58
  26. c2cciutils-1.8.0.dev45.dist-info/RECORD +37 -0
  27. {c2cciutils-1.7.0.dev174.dist-info → c2cciutils-1.8.0.dev45.dist-info}/WHEEL +1 -1
  28. {c2cciutils-1.7.0.dev174.dist-info → c2cciutils-1.8.0.dev45.dist-info}/entry_points.txt +0 -3
  29. c2cciutils/audit.py +0 -229
  30. c2cciutils/pr_checks.py +0 -286
  31. c2cciutils/scripts/audit.py +0 -41
  32. c2cciutils/scripts/docker_versions_update.py +0 -85
  33. c2cciutils/scripts/pr_checks.py +0 -78
  34. c2cciutils/security.py +0 -59
  35. c2cciutils-1.7.0.dev174.dist-info/RECORD +0 -42
c2cciutils/__init__.py CHANGED
@@ -1,6 +1,4 @@
1
- """
2
- c2cciutils shared utils function.
3
- """
1
+ """c2cciutils shared utils function."""
4
2
 
5
3
  import glob
6
4
  import json
@@ -11,7 +9,6 @@ import sys
11
9
  from re import Match, Pattern
12
10
  from typing import Any, Optional, TypedDict, cast
13
11
 
14
- import magic
15
12
  import requests
16
13
  import ruamel.yaml
17
14
 
@@ -19,10 +16,7 @@ import c2cciutils.configuration
19
16
 
20
17
 
21
18
  def get_repository() -> str:
22
- """
23
- Get the current GitHub repository like `organization/project`.
24
- """
25
-
19
+ """Get the current GitHub repository like `organization/project`."""
26
20
  if "GITHUB_REPOSITORY" in os.environ:
27
21
  return os.environ["GITHUB_REPOSITORY"]
28
22
 
@@ -46,12 +40,12 @@ def merge(default_config: Any, config: Any) -> Any:
46
40
  Arguments:
47
41
  default_config: The default config that will be applied
48
42
  config: The base config, will be modified
49
- """
50
43
 
44
+ """
51
45
  if not isinstance(default_config, dict) or not isinstance(config, dict):
52
46
  return config
53
47
 
54
- for key in default_config.keys():
48
+ for key in default_config:
55
49
  if key not in config:
56
50
  config[key] = default_config[key]
57
51
  else:
@@ -76,10 +70,7 @@ def get_master_branch(repo: list[str]) -> tuple[str, bool]:
76
70
 
77
71
 
78
72
  def get_config() -> c2cciutils.configuration.Configuration:
79
- """
80
- Get the configuration, with project and auto detections.
81
- """
82
-
73
+ """Get the configuration, with project and auto detections."""
83
74
  config: c2cciutils.configuration.Configuration = {}
84
75
  if os.path.exists("ci/config.yaml"):
85
76
  with open("ci/config.yaml", encoding="utf-8") as open_file:
@@ -129,8 +120,6 @@ def get_config() -> c2cciutils.configuration.Configuration:
129
120
 
130
121
  default_config = {
131
122
  "publish": publish_config,
132
- "pr-checks": c2cciutils.configuration.PULL_REQUEST_CHECKS_DEFAULT,
133
- "audit": c2cciutils.configuration.AUDIT_DEFAULT,
134
123
  }
135
124
  merge(default_config, config)
136
125
 
@@ -161,6 +150,7 @@ def error(
161
150
  line: The line number of the error
162
151
  col: The column number of the error
163
152
  error_type: The kind of error (error or warning)
153
+
164
154
  """
165
155
  result = ""
166
156
  on_ci = os.environ.get("CI", "false").lower() == "true"
@@ -203,6 +193,7 @@ def compile_re(config: c2cciutils.configuration.VersionTransform, prefix: str =
203
193
  prefix: The version prefix
204
194
 
205
195
  Return the compiled transform config.
196
+
206
197
  """
207
198
  result = []
208
199
  for conf in config:
@@ -232,6 +223,7 @@ def match(
232
223
 
233
224
  Returns the re match object, the matched config and the value as a tuple
234
225
  On no match it returns None, value
226
+
235
227
  """
236
228
  for conf in config:
237
229
  matched = conf["from"].match(value)
@@ -249,6 +241,7 @@ def does_match(value: str, config: list[VersionTransform]) -> bool:
249
241
  config: The result of `compile`
250
242
 
251
243
  Returns True it it does match else False
244
+
252
245
  """
253
246
  matched, _, _ = match(value, config)
254
247
  return matched is not None
@@ -268,6 +261,7 @@ def get_value(matched: Optional[Match[str]], config: Optional[VersionTransform],
268
261
  value: The default value on returned no match
269
262
 
270
263
  Return the value
264
+
271
265
  """
272
266
  return matched.expand(config.get("to", r"\1")) if matched is not None and config is not None else value
273
267
 
@@ -278,8 +272,8 @@ def print_versions(config: c2cciutils.configuration.PrintVersions) -> bool:
278
272
 
279
273
  Arguments:
280
274
  config: The print configuration
281
- """
282
275
 
276
+ """
283
277
  for version in config.get("versions", c2cciutils.configuration.PRINT_VERSIONS_VERSIONS_DEFAULT):
284
278
  try:
285
279
  sys.stdout.flush()
@@ -317,6 +311,7 @@ def gopass(key: str, default: Optional[str] = None) -> Optional[str]:
317
311
  default: the value to return if gopass is not found
318
312
 
319
313
  Return the value
314
+
320
315
  """
321
316
  try:
322
317
  return subprocess.check_output(["gopass", "show", key]).strip().decode()
@@ -333,6 +328,7 @@ def gopass_put(secret: str, key: str) -> None:
333
328
  Arguments:
334
329
  secret: The secret value
335
330
  key: The key
331
+
336
332
  """
337
333
  subprocess.check_output(["gopass", "insert", "--force", key], input=secret.encode())
338
334
 
@@ -345,6 +341,7 @@ def add_authorization_header(headers: dict[str, str]) -> dict[str, str]:
345
341
  headers: The headers
346
342
 
347
343
  Return the headers (to be chained)
344
+
348
345
  """
349
346
  try:
350
347
  token = (
@@ -382,8 +379,8 @@ def graphql(query_file: str, variables: dict[str, Any], default: Any = None) ->
382
379
 
383
380
  Return the data result
384
381
  In case of error it throw an exception
385
- """
386
382
 
383
+ """
387
384
  with open(os.path.join(os.path.dirname(__file__), query_file), encoding="utf-8") as query_open:
388
385
  query = query_open.read()
389
386
 
@@ -416,164 +413,8 @@ def graphql(query_file: str, variables: dict[str, Any], default: Any = None) ->
416
413
  return cast(dict[str, Any], json_response["data"])
417
414
 
418
415
 
419
- def get_git_files_mime(
420
- mime_type: Optional[list[str]] = None,
421
- extensions: Optional[list[str]] = None,
422
- ignore_patterns_re: Optional[list[str]] = None,
423
- ) -> list[str]:
424
- """
425
- Get list of paths from git with all the files that have the specified mime type.
426
-
427
- Arguments:
428
- mime_type: The considered MIME type
429
- extensions: The considered extensions
430
- ignore_patterns_re: A list of regular expressions of files that we should ignore
431
- """
432
- if mime_type is None:
433
- mime_type = ["text/x-python", "text/x-script.python"]
434
- if extensions is None:
435
- extensions = [".py"]
436
- ignore_patterns_compiled = [re.compile(p) for p in ignore_patterns_re or []]
437
- result = []
438
-
439
- for filename in subprocess.check_output(["git", "ls-files"]).decode().strip().split("\n"):
440
- if os.path.isfile(filename) and (
441
- os.path.splitext(filename)[1] in extensions or magic.from_file(filename, mime=True) in mime_type
442
- ):
443
- accept = True
444
- for pattern in ignore_patterns_compiled:
445
- if pattern.search(filename):
446
- accept = False
447
- break
448
- if accept:
449
- result.append(filename)
450
- return result
451
-
452
-
453
- def get_branch(branch: Optional[str], master_branch: str = "master") -> str:
454
- """
455
- Get the branch name.
456
-
457
- Arguments:
458
- branch: The forced to use branch name
459
- master_branch: The master branch name, can be used as default value
460
-
461
- Return the branch name
462
- """
463
-
464
- if branch is not None:
465
- return branch
466
- try:
467
- branch = (
468
- subprocess.run(["git", "rev-parse", "--abbrev-ref", "HEAD"], check=True, stdout=subprocess.PIPE)
469
- .stdout.decode()
470
- .strip()
471
- )
472
- except subprocess.CalledProcessError as exception:
473
- print(f"Error getting branch: {exception}")
474
- branch = "HEAD"
475
-
476
- if branch == "HEAD":
477
- branch = os.environ.get("GITHUB_HEAD_REF", master_branch)
478
- assert branch is not None
479
- return branch
480
-
481
-
482
- def get_based_on_master(
483
- repo: list[str],
484
- override_current_branch: Optional[str],
485
- master_branch: str,
486
- config: c2cciutils.configuration.Configuration,
487
- ) -> bool:
488
- """
489
- Check that we are not on a release branch (to avoid errors in versions check).
490
-
491
- This function will check the last 20 commits in current branch,
492
- and for each other branch (max 50) check if any commit in last 10 commits is the current one.
493
-
494
- Arguments:
495
- repo: The repository [<organization>, <name>]
496
- override_current_branch: The branch to use instead of the current one
497
- master_branch: The master branch name
498
- config: The full configuration
499
- """
500
- if os.environ.get("GITHUB_REF", "").startswith("refs/tags/"):
501
- # The tags are never consider as based on master
502
- return False
503
- current_branch = get_branch(override_current_branch, master_branch)
504
- if current_branch == master_branch:
505
- return True
506
- branches_re = compile_re(config["version"].get("branch_to_version_re", []))
507
- if does_match(current_branch, branches_re):
508
- return False
509
- if os.environ.get("GITHUB_BASE_REF"):
510
- return os.environ.get("GITHUB_BASE_REF") == master_branch
511
- commits_repository_json = graphql(
512
- "commits.graphql", {"name": repo[1], "owner": repo[0], "branch": current_branch}
513
- ).get("repository", {})
514
- commits_json = (
515
- commits_repository_json.get("ref", {}).get("target", {}).get("history", {}).get("nodes", [])
516
- if commits_repository_json.get("ref")
517
- else []
518
- )
519
- branches_json = [
520
- branch
521
- for branch in (
522
- graphql("branches.graphql", {"name": repo[1], "owner": repo[0]})["repository"]["refs"]["nodes"]
523
- )
524
- if branch["name"] != current_branch and does_match(branch["name"], branches_re)
525
- ]
526
- based_branch = master_branch
527
- found = False
528
- for commit in commits_json:
529
- for branch in branches_json:
530
- commits = [
531
- branch_commit
532
- for branch_commit in branch["target"]["history"]["nodes"]
533
- if commit["oid"] == branch_commit["oid"]
534
- ]
535
- if commits:
536
- based_branch = branch["name"]
537
- found = True
538
- break
539
- if found:
540
- break
541
- return based_branch == master_branch
542
-
543
-
544
- def get_codespell_command(config: c2cciutils.configuration.Configuration, fix: bool = False) -> list[str]:
545
- """
546
- Get the codespell command.
547
-
548
- Arguments:
549
- config: The full configuration
550
- fix: If we should fix the errors
551
- """
552
- codespell_config = config.get("codespell", {})
553
- codespell_config = codespell_config if isinstance(codespell_config, dict) else {}
554
- command = ["codespell"]
555
- if fix:
556
- command.append("--write-changes")
557
- for spell_ignore_file in (
558
- ".github/spell-ignore-words.txt",
559
- "spell-ignore-words.txt",
560
- ".spell-ignore-words.txt",
561
- ):
562
- if os.path.exists(spell_ignore_file):
563
- command.append(f"--ignore-words={spell_ignore_file}")
564
- break
565
- dictionaries = codespell_config.get(
566
- "internal_dictionaries", c2cciutils.configuration.CODESPELL_DICTIONARIES_DEFAULT
567
- )
568
- if dictionaries:
569
- command.append("--builtin=" + ",".join(dictionaries))
570
- command += codespell_config.get("arguments", c2cciutils.configuration.CODESPELL_ARGUMENTS_DEFAULT)
571
- return command
572
-
573
-
574
416
  def snyk_exec() -> tuple[str, dict[str, str]]:
575
417
  """Get the Snyk cli executable path."""
576
-
577
418
  if not os.path.exists(os.path.join(os.path.dirname(__file__), "node_modules")):
578
419
  subprocess.run(["npm", "install"], cwd=os.path.dirname(__file__), check=True) # nosec
579
420
 
@@ -587,59 +428,3 @@ def snyk_exec() -> tuple[str, dict[str, str]]:
587
428
  subprocess.run(["snyk", "config", "set", f"org={env['SNYK_ORG']}"], check=True, env=env)
588
429
 
589
430
  return os.path.join(os.path.dirname(os.path.abspath(__file__)), "node_modules/snyk/bin/snyk"), env
590
-
591
-
592
- def create_pull_request_if_needed(
593
- current_branch: str,
594
- new_branch: str,
595
- commit_message: str,
596
- pull_request_extra_arguments: Optional[list[str]] = None,
597
- ) -> bool:
598
- """
599
- Create a pull request if there are changes.
600
- """
601
-
602
- if pull_request_extra_arguments is None:
603
- pull_request_extra_arguments = ["--fill"]
604
-
605
- diff_proc = subprocess.run(["git", "diff", "--quiet"]) # pylint: disable=subprocess-run-check
606
- if diff_proc.returncode != 0:
607
- print("::group::Diff")
608
- sys.stdout.flush()
609
- sys.stderr.flush()
610
- subprocess.run(["git", "diff"], check=True)
611
- print("::endgroup::")
612
-
613
- git_hash = subprocess.run(
614
- ["git", "rev-parse", "HEAD"], check=True, stdout=subprocess.PIPE, encoding="utf-8"
615
- ).stdout.strip()
616
- subprocess.run(["git", "checkout", "-b", new_branch], check=True)
617
- subprocess.run(["git", "add", "--all"], check=True)
618
- subprocess.run(["git", "commit", f"--message={commit_message}"], check=True)
619
- if os.environ.get("TEST") != "TRUE":
620
- subprocess.run(
621
- ["git", "push", "--force", "origin", new_branch],
622
- check=True,
623
- )
624
- env = os.environ.copy()
625
- if "GH_TOKEN" not in env:
626
- if "GITHUB_TOKEN" in env:
627
- env["GH_TOKEN"] = env["GITHUB_TOKEN"]
628
- else:
629
- env["GH_TOKEN"] = str(c2cciutils.gopass("gs/ci/github/token/gopass"))
630
- subprocess.run(
631
- [
632
- "gh",
633
- "pr",
634
- "create",
635
- f"--base={current_branch}",
636
- *pull_request_extra_arguments,
637
- ],
638
- check=True,
639
- env=env,
640
- )
641
- else:
642
- subprocess.run(["git", "reset", "--hard"], check=True)
643
- subprocess.run(["git", "checkout", git_hash], check=True)
644
-
645
- return diff_proc.returncode != 0
@@ -1,4 +1,4 @@
1
1
  # https://docs.renovatebot.com/modules/datasource/#github-releases-datasource
2
- k3d-io/k3d: v5.6.0 # github-releases
3
- postgresql: 14.3.0 # helm - https://charts.bitnami.com/bitnami
4
- helm/chart-releaser: v1.6.1 # github-releases
2
+ k3d-io/k3d: v5.7.5 # github-releases
3
+ postgresql: 16.3.5 # helm - https://charts.bitnami.com/bitnami
4
+ helm/chart-releaser: v1.7.0 # github-releases
@@ -1,34 +1,32 @@
1
- """
2
- Automatically generated file from a JSON schema.
3
- """
1
+ """Automatically generated file from a JSON schema."""
4
2
 
5
- from typing import Literal, TypedDict, Union
3
+ from typing import Literal, TypedDict
6
4
 
7
- # Application configuration.
8
- #
9
- # An application configuration
5
+ # | Application configuration.
6
+ # |
7
+ # | An application configuration
10
8
  ApplicationConfiguration = TypedDict(
11
9
  "ApplicationConfiguration",
12
10
  {
13
- # URL pattern.
14
- #
15
- # URL pattern, to be used for files that didn't come from GitHub release, available arguments: {version}
11
+ # | URL pattern.
12
+ # |
13
+ # | URL pattern, to be used for files that didn't come from GitHub release, available arguments: {version}
16
14
  "url-pattern": str,
17
- # The type of file.
18
- #
19
- # The type of file
15
+ # | The type of file.
16
+ # |
17
+ # | The type of file
20
18
  "type": "TheTypeOfFile",
21
- # The filename to get.
22
- #
23
- # The name of the file to get in the GitHub release
19
+ # | The filename to get.
20
+ # |
21
+ # | The name of the file to get in the GitHub release
24
22
  "get-file-name": str,
25
- # The created tile name.
26
- #
27
- # The name of the final tile we will create
23
+ # | The created tile name.
24
+ # |
25
+ # | The name of the final tile we will create
28
26
  "to-file-name": str,
29
- # The tile name to get in the tar file.
27
+ # | The tile name to get in the tar file.
30
28
  "tar-file-name": str,
31
- # The commands to run after the tile creation.
29
+ # | The commands to run after the tile creation.
32
30
  "finish-commands": list[list[str]],
33
31
  },
34
32
  total=False,
@@ -43,7 +41,7 @@ All the applications configuration
43
41
  """
44
42
 
45
43
 
46
- TheTypeOfFile = Union[Literal["tar"]]
44
+ TheTypeOfFile = Literal["tar"]
47
45
  """
48
46
  The type of file.
49
47