qontract-reconcile 0.10.1rc743__py3-none-any.whl → 0.10.1rc745__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.1rc743
3
+ Version: 0.10.1rc745
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
@@ -115,7 +115,7 @@ reconcile/terraform_cloudflare_users.py,sha256=1EbTHwJgiPkJpMP-Ag340QNgGK3mXn3dc
115
115
  reconcile/terraform_repo.py,sha256=c0GZFuY3rCm6VHjHqYbsgOHrEkRWKF_1LrMThsn2XDw,16127
116
116
  reconcile/terraform_resources.py,sha256=BN8XuJwjOt1ztruEAHydkd0YiBlb3fHZ7n0snZtRhck,19356
117
117
  reconcile/terraform_tgw_attachments.py,sha256=k9Lf0ST65gmI6aUV6HnvxSGcKL7MGx_lN22OXuRGH9Y,16224
118
- reconcile/terraform_users.py,sha256=L921n4bD6-XbJeiiMKUI3quRacIkHlFEyvpi5Dcli_8,10374
118
+ reconcile/terraform_users.py,sha256=9rgbM572LfmOSnV3uCP20G_Cw6T7due94g8rhhiz904,10225
119
119
  reconcile/terraform_vpc_peerings.py,sha256=rnDH1u93OyzrBM8Hib0HwSnlxZtx4ScRQaZAcn3mx-k,25402
120
120
  reconcile/vault_replication.py,sha256=79GZ_kCimPoQcxkdhkWTQxPOAa46E0mNhf05s_Mk5so,17385
121
121
  reconcile/vpc_peerings_validator.py,sha256=Kv22HJVlTW9l9GB2eXwjPWqdDbr_VuvQBNPttox6s5o,7177
@@ -504,7 +504,7 @@ reconcile/test/test_terraform_cloudflare_users.py,sha256=RAFtMMdqZha3jNnNNsqbNQQ
504
504
  reconcile/test/test_terraform_repo.py,sha256=soKFJfF8tWIimDs39RQl3Hnh-Od-bR4PfnEA2s1UprM,11552
505
505
  reconcile/test/test_terraform_resources.py,sha256=EFCqPI5_G8hPRh1zmnU91o8wMeT2qK1CabDUa_X1rSk,15283
506
506
  reconcile/test/test_terraform_tgw_attachments.py,sha256=cAq6exc-K-jtLla1CZUZQzVnBkyDnIlL7jybnddhLKc,36861
507
- reconcile/test/test_terraform_users.py,sha256=Xn4y6EcxnNQb6XcPoOhz_Ikxmh9Nrsu88OM1scN9hzY,5434
507
+ reconcile/test/test_terraform_users.py,sha256=XOAfGvITCJPI1LTlISmHbA4ONMQMkxYUMTsny7pQCFw,4319
508
508
  reconcile/test/test_terraform_vpc_peerings.py,sha256=ubcsKh0TrUIwuI1-W3ETIgzsFvzAyeoFmEJFC-IK6JY,20538
509
509
  reconcile/test/test_terraform_vpc_peerings_build_desired_state.py,sha256=DAfpb12I0PlqnuVUHK2vh4LH4d1OylT3H2GE_3TGZZI,47852
510
510
  reconcile/test/test_three_way_diff_strategy.py,sha256=2fjEqE2w4pIzKq18PRcADTSe01aGwsZfMGloU8xfNaE,3346
@@ -663,7 +663,7 @@ reconcile/utils/throughput.py,sha256=iP4UWAe2LVhDo69mPPmgo9nQ7RxHD6_GS8MZe-aSiuM
663
663
  reconcile/utils/unleash.py,sha256=1D56CsZfE3ShDtN3IErE1T2eeIwNmxhK-yYbCotJ99E,3601
664
664
  reconcile/utils/vault.py,sha256=S0eHqvZ9N3fya1E8YDaUffEvLk_fdtpzL4rvWn6f828,14991
665
665
  reconcile/utils/vaultsecretref.py,sha256=3Ed2uBy36TzSvL0B-l4FoWQqB2SbBKDKEuUPIO608Bo,931
666
- reconcile/utils/vcs.py,sha256=o1r0n_IrU2El75CED_6sjR2GZGM-exuWsj5F7jONaMU,6779
666
+ reconcile/utils/vcs.py,sha256=uHFyYSHGpsdtiY76XVquq_5IzJTkkghBwWESeCJIeAw,8416
667
667
  reconcile/utils/acs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
668
668
  reconcile/utils/acs/base.py,sha256=kjcxLGIMe8oLNFOxZ_bDcClFqGCL7Auwug5is0yNGbw,2555
669
669
  reconcile/utils/acs/notifiers.py,sha256=2n5blP9N1FdGLZuy3do9bpjd8NKg88kmLNNqhAGn8w4,5013
@@ -777,8 +777,8 @@ tools/test/test_app_interface_metrics_exporter.py,sha256=SX7qL3D1SIRKFo95FoQztvf
777
777
  tools/test/test_qontract_cli.py,sha256=w2l4BHB09k1d-BGJ1jBUNCqDv7zkqYrMHojQXg-21kQ,4155
778
778
  tools/test/test_sd_app_sre_alert_report.py,sha256=v363r9zM7__0kR5K6mvJoGFcM9BvE33fWAayrqkpojA,2116
779
779
  tools/test/test_sre_checkpoints.py,sha256=SKqPPTl9ua0RFdSSofnoQX-JZE6dFLO3LRhfQzqtfh8,2607
780
- qontract_reconcile-0.10.1rc743.dist-info/METADATA,sha256=3porAcSIkBfriWl8PYVFIGBKGaCsF5J93rvcB__KPhc,2382
781
- qontract_reconcile-0.10.1rc743.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
782
- qontract_reconcile-0.10.1rc743.dist-info/entry_points.txt,sha256=rIxI5zWtHNlfpDeq1a7pZXAPoqf7HG32KMTN3MeWK_8,429
783
- qontract_reconcile-0.10.1rc743.dist-info/top_level.txt,sha256=l5ISPoXzt0SdR4jVdkfa7RPSKNc8zAHYWAnR-Dw8Ey8,24
784
- qontract_reconcile-0.10.1rc743.dist-info/RECORD,,
780
+ qontract_reconcile-0.10.1rc745.dist-info/METADATA,sha256=K-tNwC_Bwk22pf6PCk8t7tgUuxwXMW7XSa0kPS41UmY,2382
781
+ qontract_reconcile-0.10.1rc745.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
782
+ qontract_reconcile-0.10.1rc745.dist-info/entry_points.txt,sha256=rIxI5zWtHNlfpDeq1a7pZXAPoqf7HG32KMTN3MeWK_8,429
783
+ qontract_reconcile-0.10.1rc745.dist-info/top_level.txt,sha256=l5ISPoXzt0SdR4jVdkfa7RPSKNc8zAHYWAnR-Dw8Ey8,24
784
+ qontract_reconcile-0.10.1rc745.dist-info/RECORD,,
@@ -1,4 +1,3 @@
1
- import logging
2
1
  import sys
3
2
  from textwrap import indent
4
3
  from typing import (
@@ -113,11 +112,12 @@ def setup(
113
112
  appsre_pgp_key: Optional[str] = None,
114
113
  account_name: Optional[str] = None,
115
114
  ) -> tuple[list[dict[str, Any]], dict[str, str], bool, AWSApi]:
116
- accounts = queries.get_aws_accounts(terraform_state=True)
117
- if account_name:
118
- accounts = [n for n in accounts if n["name"] == account_name]
119
- if not accounts:
120
- raise ValueError(f"aws account {account_name} is not found")
115
+ accounts = [
116
+ a
117
+ for a in queries.get_aws_accounts(terraform_state=True)
118
+ if integration_is_enabled(QONTRACT_INTEGRATION.replace("_", "-"), a)
119
+ and (not account_name or a["name"] == account_name)
120
+ ]
121
121
  roles = get_tf_roles()
122
122
  participating_aws_accounts = _filter_participating_aws_accounts(accounts, roles)
123
123
 
@@ -253,9 +253,7 @@ def run(
253
253
  )
254
254
 
255
255
  if not accounts:
256
- logging.warning(
257
- f"No participating AWS accounts found, consider disabling this integration, account name: {account_name}"
258
- )
256
+ # no enabled accounts found
259
257
  return
260
258
 
261
259
  if print_to_file:
@@ -150,29 +150,3 @@ def test_setup(
150
150
  settings=None,
151
151
  init_users=False,
152
152
  )
153
-
154
-
155
- def test_empty_run(
156
- mocker: MockerFixture,
157
- pgp_reencryption_settings: PgpReencryptionSettingsQueryData,
158
- test_aws_account: dict,
159
- gql_api_builder: Callable[..., GqlApi],
160
- ) -> None:
161
- mocked_gql_api = gql_api_builder({"roles": []})
162
- mocker.patch("reconcile.terraform_users.gql").get_api.return_value = mocked_gql_api
163
- mocker.patch(
164
- "reconcile.terraform_users.query"
165
- ).return_value = pgp_reencryption_settings
166
- mocker.patch("reconcile.terraform_users.sys")
167
- mocked_queries = mocker.patch("reconcile.terraform_users.queries")
168
- mocked_queries.get_aws_accounts.return_value = [test_aws_account]
169
- mocked_queries.get_app_interface_settings.return_value = None
170
- mocker.patch("reconcile.terraform_users.Terrascript", autospec=True)
171
- mocker.patch("reconcile.terraform_users.AWSApi", autospec=True)
172
- mocked_logging = mocker.patch("reconcile.terraform_users.logging")
173
-
174
- integ.run(False, send_mails=False)
175
-
176
- mocked_logging.warning.assert_called_once_with(
177
- "No participating AWS accounts found, consider disabling this integration, account name: None"
178
- )
reconcile/utils/vcs.py CHANGED
@@ -3,6 +3,8 @@ from __future__ import annotations
3
3
  import logging
4
4
  import re
5
5
  from collections.abc import Iterable
6
+ from dataclasses import dataclass
7
+ from datetime import datetime
6
8
  from enum import Enum
7
9
  from typing import Optional
8
10
 
@@ -29,6 +31,13 @@ class MRCheckStatus(Enum):
29
31
  RUNNING = 3
30
32
 
31
33
 
34
+ @dataclass(order=True)
35
+ class Commit:
36
+ repo: str
37
+ sha: str
38
+ date: datetime
39
+
40
+
32
41
  class VCS:
33
42
  """
34
43
  Abstraction layer for aggregating different Version Control Systems.
@@ -46,17 +55,20 @@ class VCS:
46
55
  gitlab_instances: Iterable[GitlabInstanceV1],
47
56
  app_interface_repo_url: str,
48
57
  dry_run: bool,
49
- allow_deleting_mrs: bool,
50
- allow_opening_mrs: bool,
58
+ allow_deleting_mrs: bool = False,
59
+ allow_opening_mrs: bool = False,
51
60
  gitlab_instance: Optional[GitLabApi] = None,
52
61
  default_gh_token: Optional[str] = None,
53
62
  app_interface_api: Optional[GitLabApi] = None,
63
+ github_api_per_repo_url: Optional[dict[str, GithubRepositoryApi]] = None,
54
64
  ):
55
65
  self._dry_run = dry_run
56
66
  self._allow_deleting_mrs = allow_deleting_mrs
57
67
  self._allow_opening_mrs = allow_opening_mrs
58
68
  self._secret_reader = secret_reader
59
- self._gh_per_repo_url: dict[str, GithubRepositoryApi] = {}
69
+ self._gh_per_repo_url: dict[str, GithubRepositoryApi] = (
70
+ {} if not github_api_per_repo_url else github_api_per_repo_url
71
+ )
60
72
  self._default_gh_token = (
61
73
  default_gh_token
62
74
  if default_gh_token
@@ -151,12 +163,48 @@ class VCS:
151
163
  ) -> str:
152
164
  if bool(self._is_commit_sha_regex.search(ref)):
153
165
  return ref
154
- if "github.com" in repo_url:
166
+ if repo_url.startswith("https://github.com/"):
155
167
  github = self._init_github(repo_url=repo_url, auth_code=auth_code)
156
168
  return github.get_commit_sha(ref=ref)
157
169
  # assume gitlab by default
158
170
  return self._gitlab_instance.get_commit_sha(ref=ref, repo_url=repo_url)
159
171
 
172
+ def get_commits_between(
173
+ self,
174
+ repo_url: str,
175
+ commit_from: str,
176
+ commit_to: str,
177
+ auth_code: Optional[HasSecret],
178
+ ) -> list[Commit]:
179
+ """
180
+ Return a list of commits between two commits.
181
+ Note, that the commit_to is included in the result list, whereas commit_from is not included.
182
+ """
183
+ if repo_url.startswith("https://github.com/"):
184
+ github = self._init_github(repo_url=repo_url, auth_code=auth_code)
185
+ data = github.compare(commit_from=commit_from, commit_to=commit_to)
186
+ return [
187
+ Commit(
188
+ repo=repo_url,
189
+ sha=gh_commit.sha,
190
+ date=gh_commit.commit.committer.date,
191
+ )
192
+ for gh_commit in data
193
+ ]
194
+ # assume gitlab by default
195
+ else:
196
+ data = self._gitlab_instance.repository_compare(
197
+ repo_url=repo_url, ref_from=commit_from, ref_to=commit_to
198
+ )
199
+ return [
200
+ Commit(
201
+ repo=repo_url,
202
+ sha=gl_commit["id"],
203
+ date=datetime.fromisoformat(gl_commit["committed_date"]),
204
+ )
205
+ for gl_commit in data
206
+ ]
207
+
160
208
  def close_app_interface_mr(self, mr: ProjectMergeRequest, comment: str) -> None:
161
209
  if not self._allow_deleting_mrs:
162
210
  logging.info("Deleting MRs is disabled. Skipping.")