qontract-reconcile 0.10.1rc927__py3-none-any.whl → 0.10.1rc929__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.1rc927
3
+ Version: 0.10.1rc929
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
@@ -30,7 +30,7 @@ reconcile/github_repo_permissions_validator.py,sha256=dcbXdUx6imjNchjp3pg9-z1i7l
30
30
  reconcile/github_users.py,sha256=nfTq78QRONIfDVj-5O3bD6psllJjzWFnog-EJ1WqFPU,3672
31
31
  reconcile/github_validator.py,sha256=cVTVxJIGR4a1Jz8wrdXEAb_CMpXUzvykVmUURX4cook,917
32
32
  reconcile/gitlab_fork_compliance.py,sha256=EuF86CSUlzUQERu3CFjRujtX_dXAwSXBaWDl9Ij0LM8,4165
33
- reconcile/gitlab_housekeeping.py,sha256=gwykuBGFpCAWAl6mwbZDuGoN1Zb3zkA4szUrgZ438Eg,21288
33
+ reconcile/gitlab_housekeeping.py,sha256=5qIJPflQzwSg3iTSCw7ClEM4VHrn70WLXyYCX9vTZ7Y,22004
34
34
  reconcile/gitlab_labeler.py,sha256=a7HToXqv4S72TBp6Dmu2OkjjO60k81kH3B0J4UXHs3A,4768
35
35
  reconcile/gitlab_members.py,sha256=PrJE9OhDRdGG_gHM_77nQojLb4B18jtUu8DxgLsRS88,8417
36
36
  reconcile/gitlab_mr_sqs_consumer.py,sha256=O46mdziPgGOndbU-0_UJKJVUaiEoVzJPEgKm4_UvYoI,2571
@@ -657,7 +657,7 @@ reconcile/utils/filtering.py,sha256=S4PbMHuFr3ED0P2Q_ea5CAaB7FimI62B-F5YTaKrphA,
657
657
  reconcile/utils/git.py,sha256=actOWI2HiNpMIV6nHCzinhRa6b04Y9plWOCcPQa8lNA,1437
658
658
  reconcile/utils/git_secrets.py,sha256=y1rEhwA8DyDpBSAEuhMS7Y2X3mpxT2zQ4zyDFkhLe_g,1936
659
659
  reconcile/utils/github_api.py,sha256=R8OvqyPdnRqvP-Efnv9RvIcbBlb4M0KC4RlbnJMD0Tg,2426
660
- reconcile/utils/gitlab_api.py,sha256=ZR71p2WcKtyb4aq_K-CkWPcjtaBf64Lv6Vi79LIHvIw,30180
660
+ reconcile/utils/gitlab_api.py,sha256=1hdcT6mnlWv3mj8JIdiKSx3_uxLy-UCt_uqwZTqLyW8,30344
661
661
  reconcile/utils/gpg.py,sha256=EKG7_fdMv8BMlV5yUdPiqoTx-KrzmVSEAl2sLkaKwWI,1123
662
662
  reconcile/utils/gql.py,sha256=IGhxzBcuebbapDKLseevEThSsxa_eDCPNpo3A4VnOS4,14066
663
663
  reconcile/utils/grouping.py,sha256=vr9SFHZ7bqmHYrvYcEZt-Er3-yQYfAAdq5sHLZVmXPY,456
@@ -792,8 +792,8 @@ reconcile/utils/runtime/runner.py,sha256=PBfE_M4hTZKtyubg29AkMWlLi2KKyA74yItREtT
792
792
  reconcile/utils/runtime/sharding.py,sha256=r0ieUtNed7NvknSw6qQrCkKpVXE1shuHGnfFcnpA_k4,16142
793
793
  reconcile/utils/saasherder/__init__.py,sha256=J3MBZBFa5YmhqYm08QsjBXz8mFcVOCiOCkyIcw41t7E,343
794
794
  reconcile/utils/saasherder/interfaces.py,sha256=C2wrw34OXypshVocAsPrVZsSHptgw4g9u7Haa2wulZQ,9087
795
- reconcile/utils/saasherder/models.py,sha256=6MGie9SqsyP5ySjmk5bO5vPJ0-x53a0uzABxQO-WsB0,9746
796
- reconcile/utils/saasherder/saasherder.py,sha256=ZTDf6uIpke6y9jKZgESjdY8hDI6Jf2J2UGZp6LJXBWY,85249
795
+ reconcile/utils/saasherder/models.py,sha256=-HVTHFKXsLOew-sObHeA-6DEEyq9bQwZVXEU3MUNd4Q,9746
796
+ reconcile/utils/saasherder/saasherder.py,sha256=HDa095P6BImq4tytHW8ypdykvrEm6Ugoc36z-0RPpPM,85594
797
797
  reconcile/utils/terraform/__init__.py,sha256=zNbiyTWo35AT1sFTElL2j_AA0jJ_yWE_bfFn-nD2xik,250
798
798
  reconcile/utils/terraform/config.py,sha256=5UVrd563TMcvi4ooa5JvWVDW1I3bIWg484u79evfV_8,164
799
799
  reconcile/utils/terraform/config_client.py,sha256=3gUIIIEv52Vx7-VgQ2FZYfCCrfqUv_5gw_TQ3mbLcTs,4666
@@ -844,8 +844,8 @@ tools/test/test_qontract_cli.py,sha256=_D61RFGAN5x44CY1tYbouhlGXXABwYfxKSWSQx3Jr
844
844
  tools/test/test_saas_promotion_state.py,sha256=dy4kkSSAQ7bC0Xp2CociETGN-2aABEfL6FU5D9Jl00Y,6056
845
845
  tools/test/test_sd_app_sre_alert_report.py,sha256=v363r9zM7__0kR5K6mvJoGFcM9BvE33fWAayrqkpojA,2116
846
846
  tools/test/test_sre_checkpoints.py,sha256=SKqPPTl9ua0RFdSSofnoQX-JZE6dFLO3LRhfQzqtfh8,2607
847
- qontract_reconcile-0.10.1rc927.dist-info/METADATA,sha256=HBpJZqOcu2pa9PE_ZhB7OJrO3SGCKtUWQtZ6absL3gs,2262
848
- qontract_reconcile-0.10.1rc927.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
849
- qontract_reconcile-0.10.1rc927.dist-info/entry_points.txt,sha256=GKQqCl2j2X1BJQ69een6rHcR26PmnxnONLNOQB-nRjY,491
850
- qontract_reconcile-0.10.1rc927.dist-info/top_level.txt,sha256=l5ISPoXzt0SdR4jVdkfa7RPSKNc8zAHYWAnR-Dw8Ey8,24
851
- qontract_reconcile-0.10.1rc927.dist-info/RECORD,,
847
+ qontract_reconcile-0.10.1rc929.dist-info/METADATA,sha256=f73mvCOMsE2ga7s23FBFZeqE8xtS7encuoWL-oL1HG8,2262
848
+ qontract_reconcile-0.10.1rc929.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
849
+ qontract_reconcile-0.10.1rc929.dist-info/entry_points.txt,sha256=GKQqCl2j2X1BJQ69een6rHcR26PmnxnONLNOQB-nRjY,491
850
+ qontract_reconcile-0.10.1rc929.dist-info/top_level.txt,sha256=l5ISPoXzt0SdR4jVdkfa7RPSKNc8zAHYWAnR-Dw8Ey8,24
851
+ qontract_reconcile-0.10.1rc929.dist-info/RECORD,,
@@ -5,6 +5,7 @@ from collections.abc import (
5
5
  )
6
6
  from dataclasses import dataclass
7
7
  from datetime import (
8
+ UTC,
8
9
  datetime,
9
10
  timedelta,
10
11
  )
@@ -66,6 +67,7 @@ HOLD_LABELS = [
66
67
 
67
68
  QONTRACT_INTEGRATION = "gitlab-housekeeping"
68
69
  DATE_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"
70
+ EXPIRATION_DATE_FORMAT = "%Y-%m-%d"
69
71
 
70
72
 
71
73
  merged_merge_requests = Counter(
@@ -93,6 +95,12 @@ merge_requests_waiting = Gauge(
93
95
  labelnames=["project_id"],
94
96
  )
95
97
 
98
+ gitlab_token_expiration = Gauge(
99
+ name="qontract_reconcile_gitlab_token_expiration_days",
100
+ documentation="Time until personal access tokens expire",
101
+ labelnames=["name"],
102
+ )
103
+
96
104
 
97
105
  class InsistOnPipelineError(Exception):
98
106
  """Exception used to retry a merge when the pipeline isn't yet complete."""
@@ -542,12 +550,22 @@ def get_app_sre_usernames(gl: GitLabApi) -> set[str]:
542
550
  return {u.username for u in gl.get_app_sre_group_users()}
543
551
 
544
552
 
553
+ def publish_access_token_expiration_metrics(gl: GitLabApi) -> None:
554
+ pats = gl.get_personal_access_tokens()
555
+ for pat in pats:
556
+ expiration_date = datetime.strptime(pat.expires_at, EXPIRATION_DATE_FORMAT)
557
+ days_until_expiration = expiration_date.date() - datetime.now(UTC).date()
558
+ gitlab_token_expiration.labels(pat.name).set(days_until_expiration.days)
559
+
560
+
545
561
  def run(dry_run, wait_for_pipeline):
546
562
  default_days_interval = 15
547
563
  default_limit = 8
548
564
  default_enable_closing = False
549
565
  instance = queries.get_gitlab_instance()
550
566
  settings = queries.get_app_interface_settings()
567
+ with GitLabApi(instance, settings=settings) as gl:
568
+ publish_access_token_expiration_metrics(gl)
551
569
  repos = queries.get_repos_gitlab_housekeeping(server=instance["url"])
552
570
  app_sre_usernames: Set[str] = set()
553
571
 
@@ -29,6 +29,7 @@ from gitlab.const import (
29
29
  from gitlab.v4.objects import (
30
30
  CurrentUser,
31
31
  Group,
32
+ PersonalAccessToken,
32
33
  Project,
33
34
  ProjectIssue,
34
35
  ProjectIssueManager,
@@ -862,3 +863,6 @@ class GitLabApi: # pylint: disable=too-many-public-methods
862
863
  project = self.get_project(repo_url)
863
864
  response: Any = project.repository_compare(ref_from, ref_to)
864
865
  return response.get("commits", [])
866
+
867
+ def get_personal_access_tokens(self) -> list[PersonalAccessToken]:
868
+ return self.get_items(self.gl.personal_access_tokens.list)
@@ -272,7 +272,7 @@ class TargetSpec:
272
272
  def delete(self) -> bool:
273
273
  return bool(self.target.delete)
274
274
 
275
- def parameters(self, adjust: bool = True) -> dict[str, str]:
275
+ def parameters(self, adjust: bool = True) -> dict[str, Any]:
276
276
  environment_parameters = self._collect_parameters(
277
277
  self.target.namespace.environment, adjust=adjust
278
278
  )
@@ -984,11 +984,16 @@ class SaasHerder: # pylint: disable=too-many-public-methods
984
984
  else True
985
985
  )
986
986
  html_url = f"{url}/tree/{target.ref}{path}"
987
+ consolidated_parameters = spec.parameters(adjust=False)
988
+ if not consolidated_parameters.get("image", {}).get("tag"):
989
+ commit_sha = self._get_commit_sha(url, target.ref, github)
990
+ image_tag = commit_sha[:hash_length]
991
+ consolidated_parameters.setdefault("image", {})["tag"] = image_tag
987
992
  resources = helm.template_all(
988
993
  url=url,
989
994
  path=path,
990
995
  name=resource_template_name,
991
- values=spec.parameters(adjust=False),
996
+ values=consolidated_parameters,
992
997
  ssl_verify=ssl_verify,
993
998
  )
994
999