qontract-reconcile 0.10.1rc1111__py3-none-any.whl → 0.10.1rc1113__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: qontract-reconcile
3
- Version: 0.10.1rc1111
3
+ Version: 0.10.1rc1113
4
4
  Summary: Collection of tools to reconcile services with their desired state as defined in the app-interface DB.
5
5
  Home-page: https://github.com/app-sre/qontract-reconcile
6
6
  Author: Red Hat App-SRE Team
@@ -676,14 +676,13 @@ reconcile/utils/extended_early_exit.py,sha256=QSktrmfw37zSRMNk930tDbQsVeKxaPPPD4
676
676
  reconcile/utils/external_resource_spec.py,sha256=bhH_xneFwATdFumTPkiQmcVKYI0gcaWuqV6FpFdf_P0,7006
677
677
  reconcile/utils/external_resources.py,sha256=GC4wYuSXwk2ifr3aDEwnEiumaYqWhzgKK-hXp6pXemA,7516
678
678
  reconcile/utils/filtering.py,sha256=S4PbMHuFr3ED0P2Q_ea5CAaB7FimI62B-F5YTaKrphA,402
679
- reconcile/utils/git.py,sha256=JkpbUO10oBTtNHZ1IhjyG6dTOUizc7I5H0vm7NvDVNw,1409
680
- reconcile/utils/git_secrets.py,sha256=y1rEhwA8DyDpBSAEuhMS7Y2X3mpxT2zQ4zyDFkhLe_g,1936
679
+ reconcile/utils/git.py,sha256=wzVIYAeKlMGW538U1mkJWUI6h_mFRUY4lawh2AR8hw4,2345
681
680
  reconcile/utils/github_api.py,sha256=R8OvqyPdnRqvP-Efnv9RvIcbBlb4M0KC4RlbnJMD0Tg,2426
682
681
  reconcile/utils/gitlab_api.py,sha256=C1nsHQKKybsmFdaG9vsItBjJm69ym4VWbqbKfAEf7oY,29305
683
682
  reconcile/utils/gpg.py,sha256=EKG7_fdMv8BMlV5yUdPiqoTx-KrzmVSEAl2sLkaKwWI,1123
684
683
  reconcile/utils/gql.py,sha256=C0thIm_k9MBldfqwHzyqtYZk9sIvMdm9IbbnXLGwjD8,14158
685
684
  reconcile/utils/grouping.py,sha256=vr9SFHZ7bqmHYrvYcEZt-Er3-yQYfAAdq5sHLZVmXPY,456
686
- reconcile/utils/helm.py,sha256=cbvmmdjtfPfHhD5SPqf922P6IKO4Ll9FYiCAIRfQtTk,3830
685
+ reconcile/utils/helm.py,sha256=hr4J_9mBZwbc1FDNfFh4QKAj0h3eLxyTN2Y3UxIRp8U,3893
687
686
  reconcile/utils/helpers.py,sha256=k9svgFFZG7H5FvHYY0g5jJyvgvh2UDZxf0Ib221teag,1179
688
687
  reconcile/utils/imap_client.py,sha256=h8YDiCSCvroErhpH_-KGYI7Y2WU2Q2oSpuxDFbOkSbY,1989
689
688
  reconcile/utils/instrumented_wrappers.py,sha256=eVwMoa6FCrYxLv3RML3WpZF9qKVfCTjMxphgVXG03OM,1073
@@ -819,7 +818,7 @@ reconcile/utils/runtime/sharding.py,sha256=r0ieUtNed7NvknSw6qQrCkKpVXE1shuHGnfFc
819
818
  reconcile/utils/saasherder/__init__.py,sha256=3U8plqMAPRE1kjwZ5YnIsYsggTf4_gS7flRUEuXVBAs,343
820
819
  reconcile/utils/saasherder/interfaces.py,sha256=C2wrw34OXypshVocAsPrVZsSHptgw4g9u7Haa2wulZQ,9087
821
820
  reconcile/utils/saasherder/models.py,sha256=z8ln03zi2a8cu716NcNUDHp8Dv1VcVbhqdWVxCl7x9A,10148
822
- reconcile/utils/saasherder/saasherder.py,sha256=dG7Qw4lMkU-3YMKZDNnXBdJQV9kdfVe984R_8iwR_eU,85333
821
+ reconcile/utils/saasherder/saasherder.py,sha256=t7dqcXj9FFULROG_gUmdoSNQOLKfhdlquzwxw710yOA,85358
823
822
  reconcile/utils/terraform/__init__.py,sha256=zNbiyTWo35AT1sFTElL2j_AA0jJ_yWE_bfFn-nD2xik,250
824
823
  reconcile/utils/terraform/config.py,sha256=5UVrd563TMcvi4ooa5JvWVDW1I3bIWg484u79evfV_8,164
825
824
  reconcile/utils/terraform/config_client.py,sha256=gRL1rQ0AqvShei_rcGqC3HDYGskOFKE1nPrJyJE9yno,4676
@@ -870,8 +869,8 @@ tools/test/test_qontract_cli.py,sha256=_D61RFGAN5x44CY1tYbouhlGXXABwYfxKSWSQx3Jr
870
869
  tools/test/test_saas_promotion_state.py,sha256=dy4kkSSAQ7bC0Xp2CociETGN-2aABEfL6FU5D9Jl00Y,6056
871
870
  tools/test/test_sd_app_sre_alert_report.py,sha256=v363r9zM7__0kR5K6mvJoGFcM9BvE33fWAayrqkpojA,2116
872
871
  tools/test/test_sre_checkpoints.py,sha256=SKqPPTl9ua0RFdSSofnoQX-JZE6dFLO3LRhfQzqtfh8,2607
873
- qontract_reconcile-0.10.1rc1111.dist-info/METADATA,sha256=MRxULyQA4iDeQKW4d2ofSRt-E4W28UKdZFgCRYKINCs,2213
874
- qontract_reconcile-0.10.1rc1111.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
875
- qontract_reconcile-0.10.1rc1111.dist-info/entry_points.txt,sha256=GKQqCl2j2X1BJQ69een6rHcR26PmnxnONLNOQB-nRjY,491
876
- qontract_reconcile-0.10.1rc1111.dist-info/top_level.txt,sha256=l5ISPoXzt0SdR4jVdkfa7RPSKNc8zAHYWAnR-Dw8Ey8,24
877
- qontract_reconcile-0.10.1rc1111.dist-info/RECORD,,
872
+ qontract_reconcile-0.10.1rc1113.dist-info/METADATA,sha256=LJxCt1WmYLBNl5XvtV_mNedg6BB6ETu4q7Ojm8WUfaE,2213
873
+ qontract_reconcile-0.10.1rc1113.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
874
+ qontract_reconcile-0.10.1rc1113.dist-info/entry_points.txt,sha256=GKQqCl2j2X1BJQ69een6rHcR26PmnxnONLNOQB-nRjY,491
875
+ qontract_reconcile-0.10.1rc1113.dist-info/top_level.txt,sha256=l5ISPoXzt0SdR4jVdkfa7RPSKNc8zAHYWAnR-Dw8Ey8,24
876
+ qontract_reconcile-0.10.1rc1113.dist-info/RECORD,,
reconcile/utils/git.py CHANGED
@@ -19,11 +19,45 @@ def clone(repo_url, wd, depth=None, verify=True):
19
19
  raise GitError(f"git clone failed: {repo_url}")
20
20
 
21
21
 
22
- def checkout(commit, wd):
23
- cmd = ["git", "checkout", commit]
24
- result = subprocess.run(cmd, cwd=wd, capture_output=True, check=False)
22
+ def rev_parse(ref: str, wd: str) -> str:
23
+ cmd = ["git", "rev-parse", ref]
24
+ result = subprocess.run(cmd, cwd=wd, capture_output=True, text=True, check=True)
25
+ return result.stdout.strip()
26
+
27
+
28
+ def is_current_ref(ref: str, wd: str) -> bool:
29
+ return rev_parse("HEAD", wd) == rev_parse(ref, wd)
30
+
31
+
32
+ def fetch(
33
+ ref: str,
34
+ wd: str,
35
+ remote: str = "origin",
36
+ depth: int | None = None,
37
+ verify: bool = True,
38
+ ):
39
+ cmd = ["git"]
40
+ if not verify:
41
+ cmd += ["-c", "http.sslVerify=false"]
42
+ cmd += ["fetch", remote, ref]
43
+ if depth:
44
+ cmd += ["--depth", str(depth)]
45
+ result = subprocess.run(cmd, cwd=wd, capture_output=True, text=True, check=False)
46
+ if result.returncode != 0:
47
+ raise GitError(f"git fetch failed for {ref}: {result.stderr}")
48
+
49
+
50
+ def checkout(
51
+ ref: str,
52
+ wd: str,
53
+ verify: bool = True,
54
+ ):
55
+ if not is_current_ref(ref, wd):
56
+ fetch(ref, wd, depth=1, verify=verify)
57
+ cmd = ["git", "checkout", ref]
58
+ result = subprocess.run(cmd, cwd=wd, capture_output=True, text=True, check=False)
25
59
  if result.returncode != 0:
26
- raise GitError(f"git checkout failed: {commit}")
60
+ raise GitError(f"git checkout failed for {ref}: {result.stderr}")
27
61
 
28
62
 
29
63
  def is_file_in_git_repo(file_path):
reconcile/utils/helm.py CHANGED
@@ -108,12 +108,14 @@ def template(
108
108
  def template_all(
109
109
  url: str,
110
110
  path: str,
111
+ ref: str,
111
112
  namespace: str,
112
113
  values: Mapping[str, Any],
113
114
  ssl_verify: bool = True,
114
115
  ) -> Iterable[Mapping[str, Any]]:
115
116
  with tempfile.TemporaryDirectory() as wd:
116
117
  git.clone(url, wd, depth=1, verify=ssl_verify)
118
+ git.checkout(ref, wd, verify=ssl_verify)
117
119
  return yaml.safe_load_all(
118
120
  do_template(values=values, path=f"{wd}{path}", namespace=namespace)
119
121
  )
@@ -979,6 +979,7 @@ class SaasHerder: # pylint: disable=too-many-public-methods
979
979
  resources = helm.template_all(
980
980
  url=url,
981
981
  path=path,
982
+ ref=ref,
982
983
  namespace=spec.target.namespace.name,
983
984
  values=consolidated_parameters,
984
985
  ssl_verify=ssl_verify,
@@ -1,63 +0,0 @@
1
- import logging
2
- import os
3
- import subprocess
4
- import tempfile
5
-
6
- import requests
7
- from sretoolbox.utils import retry
8
-
9
- from reconcile.utils import git
10
-
11
-
12
- @retry()
13
- def scan_history(repo_url, existing_keys):
14
- logging.info(f"scanning {repo_url}")
15
- if requests.get(repo_url, timeout=60).status_code == 404:
16
- logging.info(f"not found {repo_url}")
17
- return []
18
-
19
- with tempfile.TemporaryDirectory() as wd:
20
- git.clone(repo_url, wd)
21
- subprocess.run(["git", "secrets", "--install"], check=False, cwd=wd)
22
- result = subprocess.run(
23
- ["git", "secrets", "--scan-history"],
24
- capture_output=True,
25
- check=False,
26
- cwd=wd,
27
- )
28
- if result.returncode == 0:
29
- return []
30
- logging.info(f"found suspects in {repo_url}")
31
- suspected_files = get_suspected_files(result.stderr.decode("utf-8"))
32
- leaked_keys = get_leaked_keys(wd, suspected_files, existing_keys)
33
- if leaked_keys:
34
- logging.info(f"found suspected leaked keys: {leaked_keys}")
35
- return leaked_keys
36
-
37
-
38
- def get_suspected_files(error):
39
- suspects = []
40
- for e in error.split("\n"):
41
- if not e:
42
- break
43
- if e.startswith("warning"):
44
- continue
45
- commit_path_split = e.split(" ")[0].split(":")
46
- commit, path = commit_path_split[0], commit_path_split[1]
47
-
48
- suspects.append((commit, path))
49
- return set(suspects)
50
-
51
-
52
- def get_leaked_keys(repo_wd, suspected_files, existing_keys):
53
- all_leaked_keys = []
54
- for s in suspected_files:
55
- commit, file_relative_path = s[0], s[1]
56
- git.checkout(commit, repo_wd)
57
- file_path = os.path.join(repo_wd, file_relative_path)
58
- with open(file_path, encoding="locale") as f:
59
- content = f.read()
60
- leaked_keys = [key for key in existing_keys if key in content]
61
- all_leaked_keys.extend(leaked_keys)
62
-
63
- return all_leaked_keys