qontract-reconcile 0.10.1rc928__py3-none-any.whl → 0.10.1rc930__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.1rc928
3
+ Version: 0.10.1rc930
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
@@ -813,7 +813,7 @@ tools/app_interface_metrics_exporter.py,sha256=zkwkxdAUAxjdc-pzx2_oJXG25fo0Fnyd5
813
813
  tools/app_interface_reporter.py,sha256=uy9eRHf6EdvD8ZY2WYdroGXm18DOdnqVZyxaWN3Bm_0,17724
814
814
  tools/glitchtip_access_reporter.py,sha256=oPBnk_YoDuljU3v0FaChzOwwnk4vap1xEE67QEjzdqs,2948
815
815
  tools/glitchtip_access_revalidation.py,sha256=8kbBJk04mkq28kWoRDDkfCGIF3GRg3pJrFAh1sW0dbk,2821
816
- tools/qontract_cli.py,sha256=lEjrFQSUHDRYrIbQ96ncwjiIqNVqW8lZrpzy8_V_pFo,124262
816
+ tools/qontract_cli.py,sha256=mBQpTirTnjAZcywEreXIufLHQHb7o4UpHy7ulw_5JyE,124302
817
817
  tools/sd_app_sre_alert_report.py,sha256=e9vAdyenUz2f5c8-z-5WY0wv-SJ9aePKDH2r4IwB6pc,5063
818
818
  tools/template_validation.py,sha256=qpKYaTgk0GOPGa2Ct5_5sKdwIHtCAKIBGzsMPuJU5fw,3371
819
819
  tools/cli_commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -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.1rc928.dist-info/METADATA,sha256=TDSUBhjq6BnvT5oCsC8bY7bLAypm61Exrn9fWkPgCWA,2262
848
- qontract_reconcile-0.10.1rc928.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
849
- qontract_reconcile-0.10.1rc928.dist-info/entry_points.txt,sha256=GKQqCl2j2X1BJQ69een6rHcR26PmnxnONLNOQB-nRjY,491
850
- qontract_reconcile-0.10.1rc928.dist-info/top_level.txt,sha256=l5ISPoXzt0SdR4jVdkfa7RPSKNc8zAHYWAnR-Dw8Ey8,24
851
- qontract_reconcile-0.10.1rc928.dist-info/RECORD,,
847
+ qontract_reconcile-0.10.1rc930.dist-info/METADATA,sha256=xtxwwU4zI2Y8Y5dzVHggmbkLfH6KQuSLBzeW77oHGwk,2262
848
+ qontract_reconcile-0.10.1rc930.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
849
+ qontract_reconcile-0.10.1rc930.dist-info/entry_points.txt,sha256=GKQqCl2j2X1BJQ69een6rHcR26PmnxnONLNOQB-nRjY,491
850
+ qontract_reconcile-0.10.1rc930.dist-info/top_level.txt,sha256=l5ISPoXzt0SdR4jVdkfa7RPSKNc8zAHYWAnR-Dw8Ey8,24
851
+ qontract_reconcile-0.10.1rc930.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)
tools/qontract_cli.py CHANGED
@@ -2032,7 +2032,7 @@ def app_interface_review_queue(ctx) -> None:
2032
2032
  ):
2033
2033
  continue
2034
2034
 
2035
- pipelines = mr.pipelines()
2035
+ pipelines = gl.get_merge_request_pipelines(mr)
2036
2036
  if not pipelines:
2037
2037
  continue
2038
2038
  running_pipelines = [p for p in pipelines if p["status"] == "running"]
@@ -2129,7 +2129,7 @@ def app_interface_open_selfserviceable_mr_queue(ctx):
2129
2129
  continue
2130
2130
 
2131
2131
  # skip MRs where the pipeline is still running or where it failed
2132
- pipelines = mr.pipelines()
2132
+ pipelines = gl.get_merge_request_pipelines(mr)
2133
2133
  if not pipelines:
2134
2134
  continue
2135
2135
  running_pipelines = [p for p in pipelines if p["status"] == "running"]