qontract-reconcile 0.10.2.dev56__py3-none-any.whl → 0.10.2.dev57__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.
- {qontract_reconcile-0.10.2.dev56.dist-info → qontract_reconcile-0.10.2.dev57.dist-info}/METADATA +1 -1
- {qontract_reconcile-0.10.2.dev56.dist-info → qontract_reconcile-0.10.2.dev57.dist-info}/RECORD +26 -25
- reconcile/aws_cloudwatch_log_retention/integration.py +17 -10
- reconcile/dashdotdb_dora.py +4 -5
- reconcile/gitlab_housekeeping.py +6 -10
- reconcile/terraform_tgw_attachments.py +5 -5
- reconcile/terraform_vpc_peerings.py +1 -1
- reconcile/utils/aggregated_list.py +20 -30
- reconcile/utils/aws_api.py +168 -595
- reconcile/utils/aws_helper.py +7 -7
- reconcile/utils/binary.py +7 -14
- reconcile/utils/config.py +6 -9
- reconcile/utils/data_structures.py +13 -0
- reconcile/utils/defer.py +2 -4
- reconcile/utils/elasticsearch_exceptions.py +4 -7
- reconcile/utils/environ.py +3 -5
- reconcile/utils/exceptions.py +2 -5
- reconcile/utils/git.py +4 -6
- reconcile/utils/gitlab_api.py +82 -103
- reconcile/utils/mr/base.py +3 -6
- reconcile/utils/mr/update_access_report_base.py +2 -2
- reconcile/utils/vcs.py +3 -5
- reconcile/vpc_peerings_validator.py +15 -21
- tools/qontract_cli.py +17 -26
- {qontract_reconcile-0.10.2.dev56.dist-info → qontract_reconcile-0.10.2.dev57.dist-info}/WHEEL +0 -0
- {qontract_reconcile-0.10.2.dev56.dist-info → qontract_reconcile-0.10.2.dev57.dist-info}/entry_points.txt +0 -0
reconcile/utils/gitlab_api.py
CHANGED
@@ -2,9 +2,7 @@ import logging
|
|
2
2
|
import os
|
3
3
|
import re
|
4
4
|
from collections.abc import (
|
5
|
-
Callable,
|
6
5
|
Iterable,
|
7
|
-
Mapping,
|
8
6
|
Set,
|
9
7
|
)
|
10
8
|
from functools import cached_property
|
@@ -14,8 +12,6 @@ from operator import (
|
|
14
12
|
)
|
15
13
|
from typing import (
|
16
14
|
Any,
|
17
|
-
Protocol,
|
18
|
-
Self,
|
19
15
|
TypedDict,
|
20
16
|
cast,
|
21
17
|
)
|
@@ -29,7 +25,6 @@ from gitlab.const import (
|
|
29
25
|
MAINTAINER_ACCESS,
|
30
26
|
OWNER_ACCESS,
|
31
27
|
REPORTER_ACCESS,
|
32
|
-
AccessLevel,
|
33
28
|
)
|
34
29
|
from gitlab.v4.objects import (
|
35
30
|
CurrentUser,
|
@@ -37,20 +32,16 @@ from gitlab.v4.objects import (
|
|
37
32
|
GroupMember,
|
38
33
|
PersonalAccessToken,
|
39
34
|
Project,
|
40
|
-
ProjectFile,
|
41
|
-
ProjectHook,
|
42
35
|
ProjectIssue,
|
43
36
|
ProjectIssueManager,
|
44
37
|
ProjectMergeRequest,
|
45
38
|
ProjectMergeRequestManager,
|
46
39
|
ProjectMergeRequestNote,
|
47
|
-
ProjectMergeRequestResourceLabelEvent,
|
48
|
-
User,
|
49
40
|
)
|
50
41
|
from sretoolbox.utils import retry
|
51
42
|
|
52
43
|
from reconcile.utils.metrics import gitlab_request
|
53
|
-
from reconcile.utils.secret_reader import SecretReader
|
44
|
+
from reconcile.utils.secret_reader import SecretReader
|
54
45
|
|
55
46
|
# The following line will suppress
|
56
47
|
# `InsecureRequestWarning: Unverified HTTPS request is being made`
|
@@ -99,20 +90,16 @@ class GLGroupMember(TypedDict):
|
|
99
90
|
access_level: str
|
100
91
|
|
101
92
|
|
102
|
-
class
|
103
|
-
user: str
|
104
|
-
access_level: int
|
105
|
-
|
106
|
-
|
107
|
-
class GitLabApi:
|
93
|
+
class GitLabApi: # pylint: disable=too-many-public-methods
|
108
94
|
def __init__(
|
109
95
|
self,
|
110
|
-
instance
|
111
|
-
project_id
|
112
|
-
settings
|
113
|
-
secret_reader
|
114
|
-
project_url
|
115
|
-
|
96
|
+
instance,
|
97
|
+
project_id=None,
|
98
|
+
settings=None,
|
99
|
+
secret_reader=None,
|
100
|
+
project_url=None,
|
101
|
+
saas_files=None,
|
102
|
+
timeout=30,
|
116
103
|
):
|
117
104
|
self.server = instance["url"]
|
118
105
|
if not secret_reader:
|
@@ -128,7 +115,6 @@ class GitLabApi:
|
|
128
115
|
timeout=timeout,
|
129
116
|
)
|
130
117
|
self._auth()
|
131
|
-
assert self.gl.user
|
132
118
|
self.user: CurrentUser = self.gl.user
|
133
119
|
if project_id is None:
|
134
120
|
# When project_id is not provide, we try to get the project
|
@@ -141,6 +127,7 @@ class GitLabApi:
|
|
141
127
|
else:
|
142
128
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
143
129
|
self.project = self.gl.projects.get(project_id)
|
130
|
+
self.saas_files = saas_files
|
144
131
|
|
145
132
|
@cached_property
|
146
133
|
def project_main_branch(self) -> str:
|
@@ -151,40 +138,38 @@ class GitLabApi:
|
|
151
138
|
|
152
139
|
@property
|
153
140
|
def main_branch(self) -> str:
|
154
|
-
return self.project_main_branch
|
141
|
+
return self.project_main_branch if self.project else DEFAULT_MAIN_BRANCH
|
155
142
|
|
156
|
-
def __enter__(self)
|
143
|
+
def __enter__(self):
|
157
144
|
return self
|
158
145
|
|
159
|
-
def __exit__(self, *exc
|
146
|
+
def __exit__(self, *exc):
|
160
147
|
self.cleanup()
|
161
148
|
|
162
|
-
def __str__(self)
|
149
|
+
def __str__(self):
|
163
150
|
return self.project.web_url
|
164
151
|
|
165
|
-
def cleanup(self)
|
152
|
+
def cleanup(self):
|
166
153
|
"""
|
167
154
|
Close gl session.
|
168
155
|
"""
|
169
156
|
self.gl.session.close()
|
170
157
|
|
171
158
|
@retry()
|
172
|
-
def _auth(self)
|
159
|
+
def _auth(self):
|
173
160
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
174
161
|
self.gl.auth()
|
175
162
|
|
176
|
-
def create_branch(self, new_branch
|
163
|
+
def create_branch(self, new_branch, source_branch):
|
177
164
|
data = {"branch": new_branch, "ref": source_branch}
|
178
165
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
179
166
|
self.project.branches.create(data)
|
180
167
|
|
181
|
-
def delete_branch(self, branch
|
168
|
+
def delete_branch(self, branch):
|
182
169
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
183
170
|
self.project.branches.delete(branch)
|
184
171
|
|
185
|
-
def create_commit(
|
186
|
-
self, branch_name: str, commit_message: str, actions: Iterable[Mapping]
|
187
|
-
) -> None:
|
172
|
+
def create_commit(self, branch_name, commit_message, actions):
|
188
173
|
"""
|
189
174
|
actions is a list of 'action' dictionaries. The 'action' dict is
|
190
175
|
documented here: https://docs.gitlab.com/ee/api/commits.html
|
@@ -198,9 +183,7 @@ class GitLabApi:
|
|
198
183
|
"actions": actions,
|
199
184
|
})
|
200
185
|
|
201
|
-
def create_file(
|
202
|
-
self, branch_name: str, file_path: str, commit_message: str, content: str
|
203
|
-
) -> None:
|
186
|
+
def create_file(self, branch_name, file_path, commit_message, content):
|
204
187
|
data = {
|
205
188
|
"branch": branch_name,
|
206
189
|
"commit_message": commit_message,
|
@@ -211,9 +194,7 @@ class GitLabApi:
|
|
211
194
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
212
195
|
self.project.commits.create(data)
|
213
196
|
|
214
|
-
def delete_file(
|
215
|
-
self, branch_name: str, file_path: str, commit_message: str
|
216
|
-
) -> None:
|
197
|
+
def delete_file(self, branch_name, file_path, commit_message):
|
217
198
|
data = {
|
218
199
|
"branch": branch_name,
|
219
200
|
"commit_message": commit_message,
|
@@ -222,9 +203,7 @@ class GitLabApi:
|
|
222
203
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
223
204
|
self.project.commits.create(data)
|
224
205
|
|
225
|
-
def update_file(
|
226
|
-
self, branch_name: str, file_path: str, commit_message: str, content: str
|
227
|
-
) -> None:
|
206
|
+
def update_file(self, branch_name, file_path, commit_message, content):
|
228
207
|
data = {
|
229
208
|
"branch": branch_name,
|
230
209
|
"commit_message": commit_message,
|
@@ -237,12 +216,12 @@ class GitLabApi:
|
|
237
216
|
|
238
217
|
def create_mr(
|
239
218
|
self,
|
240
|
-
source_branch
|
241
|
-
target_branch
|
242
|
-
title
|
243
|
-
remove_source_branch
|
244
|
-
labels
|
245
|
-
)
|
219
|
+
source_branch,
|
220
|
+
target_branch,
|
221
|
+
title,
|
222
|
+
remove_source_branch=True,
|
223
|
+
labels=None,
|
224
|
+
):
|
246
225
|
if labels is None:
|
247
226
|
labels = []
|
248
227
|
data = {
|
@@ -253,7 +232,7 @@ class GitLabApi:
|
|
253
232
|
"labels": labels,
|
254
233
|
}
|
255
234
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
256
|
-
return
|
235
|
+
return self.project.mergerequests.create(data)
|
257
236
|
|
258
237
|
def mr_exists(self, title: str) -> bool:
|
259
238
|
mrs = self.get_merge_requests(state=MRState.OPENED)
|
@@ -274,7 +253,7 @@ class GitLabApi:
|
|
274
253
|
members = self.get_items(project.members_all.list)
|
275
254
|
return [m.username for m in members if m.access_level >= 40]
|
276
255
|
|
277
|
-
def get_app_sre_group_users(self)
|
256
|
+
def get_app_sre_group_users(self):
|
278
257
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
279
258
|
app_sre_group = self.gl.groups.get("app-sre")
|
280
259
|
return self.get_items(app_sre_group.members.list)
|
@@ -325,9 +304,7 @@ class GitLabApi:
|
|
325
304
|
if not self._is_bot_username(m.username)
|
326
305
|
]
|
327
306
|
|
328
|
-
def add_project_member(
|
329
|
-
self, repo_url: str, user: GroupMember, access: str = "maintainer"
|
330
|
-
) -> None:
|
307
|
+
def add_project_member(self, repo_url, user, access="maintainer"):
|
331
308
|
project = self.get_project(repo_url)
|
332
309
|
if project is None:
|
333
310
|
return
|
@@ -339,7 +316,7 @@ class GitLabApi:
|
|
339
316
|
member.access_level = access_level
|
340
317
|
member.save()
|
341
318
|
|
342
|
-
def add_group_member(self, group
|
319
|
+
def add_group_member(self, group, user):
|
343
320
|
gitlab_user = self.get_user(user.user)
|
344
321
|
if gitlab_user is not None:
|
345
322
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
@@ -354,34 +331,41 @@ class GitLabApi:
|
|
354
331
|
member.access_level = user.access_level
|
355
332
|
member.save()
|
356
333
|
|
357
|
-
def remove_group_member(self, group
|
334
|
+
def remove_group_member(self, group, user_id):
|
358
335
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
359
336
|
group.members.delete(user_id)
|
360
337
|
|
361
|
-
def change_access(self, member
|
338
|
+
def change_access(self, member, access_level):
|
362
339
|
member.access_level = access_level
|
363
340
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
364
341
|
member.save()
|
365
342
|
|
366
343
|
@staticmethod
|
367
|
-
def get_access_level_string(access_level
|
368
|
-
|
344
|
+
def get_access_level_string(access_level):
|
345
|
+
if access_level == OWNER_ACCESS:
|
346
|
+
return "owner"
|
347
|
+
if access_level == MAINTAINER_ACCESS:
|
348
|
+
return "maintainer"
|
349
|
+
if access_level == DEVELOPER_ACCESS:
|
350
|
+
return "developer"
|
351
|
+
if access_level == REPORTER_ACCESS:
|
352
|
+
return "reporter"
|
353
|
+
if access_level == GUEST_ACCESS:
|
354
|
+
return "guest"
|
369
355
|
|
370
356
|
@staticmethod
|
371
|
-
def get_access_level(access
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
case _:
|
384
|
-
raise ValueError(f"Invalid access level: {access}")
|
357
|
+
def get_access_level(access):
|
358
|
+
access = access.lower()
|
359
|
+
if access == "owner":
|
360
|
+
return OWNER_ACCESS
|
361
|
+
if access == "maintainer":
|
362
|
+
return MAINTAINER_ACCESS
|
363
|
+
if access == "developer":
|
364
|
+
return DEVELOPER_ACCESS
|
365
|
+
if access == "reporter":
|
366
|
+
return REPORTER_ACCESS
|
367
|
+
if access == "guest":
|
368
|
+
return GUEST_ACCESS
|
385
369
|
|
386
370
|
def get_group_id_and_projects(self, group_name: str) -> tuple[str, list[str]]:
|
387
371
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
@@ -392,11 +376,11 @@ class GitLabApi:
|
|
392
376
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
393
377
|
return self.gl.groups.get(group_name)
|
394
378
|
|
395
|
-
def create_project(self, group_id
|
379
|
+
def create_project(self, group_id, project):
|
396
380
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
397
381
|
self.gl.projects.create({"name": project, "namespace_id": group_id})
|
398
382
|
|
399
|
-
def get_project_url(self, group
|
383
|
+
def get_project_url(self, group, project):
|
400
384
|
return f"{self.server}/{group}/{project}"
|
401
385
|
|
402
386
|
@retry()
|
@@ -414,19 +398,17 @@ class GitLabApi:
|
|
414
398
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
415
399
|
return self.gl.projects.get(project_id)
|
416
400
|
|
417
|
-
def get_issues(self, state
|
401
|
+
def get_issues(self, state):
|
418
402
|
return self.get_items(self.project.issues.list, state=state)
|
419
403
|
|
420
|
-
def get_merge_request(self, mr_id
|
404
|
+
def get_merge_request(self, mr_id):
|
421
405
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
422
406
|
return self.project.mergerequests.get(mr_id)
|
423
407
|
|
424
|
-
def get_merge_requests(self, state
|
408
|
+
def get_merge_requests(self, state):
|
425
409
|
return self.get_items(self.project.mergerequests.list, state=state)
|
426
410
|
|
427
|
-
def get_merge_request_label_events(
|
428
|
-
self, mr: ProjectMergeRequest
|
429
|
-
) -> list[ProjectMergeRequestResourceLabelEvent]:
|
411
|
+
def get_merge_request_label_events(self, mr: ProjectMergeRequest):
|
430
412
|
return self.get_items(mr.resourcelabelevents.list)
|
431
413
|
|
432
414
|
def get_merge_request_pipelines(self, mr: ProjectMergeRequest) -> list[dict]:
|
@@ -524,7 +506,7 @@ class GitLabApi:
|
|
524
506
|
def add_labels_to_merge_request(
|
525
507
|
merge_request: ProjectMergeRequest,
|
526
508
|
labels: Iterable[str],
|
527
|
-
)
|
509
|
+
):
|
528
510
|
"""Adds labels to a Merge Request"""
|
529
511
|
# merge_request maybe stale, refresh it to reduce the possibility of labels overwriting
|
530
512
|
GitLabApi.refresh_labels(merge_request)
|
@@ -575,7 +557,7 @@ class GitLabApi:
|
|
575
557
|
|
576
558
|
# TODO: deprecated this method as new support of list(get_all=True), and figure out request counter metrics
|
577
559
|
@staticmethod
|
578
|
-
def get_items(method
|
560
|
+
def get_items(method, **kwargs):
|
579
561
|
all_items = []
|
580
562
|
page = 1
|
581
563
|
while True:
|
@@ -593,7 +575,7 @@ class GitLabApi:
|
|
593
575
|
self.project.labels.create({"name": label_text, "color": label_color})
|
594
576
|
|
595
577
|
@staticmethod
|
596
|
-
def refresh_labels(item: ProjectMergeRequest | ProjectIssue)
|
578
|
+
def refresh_labels(item: ProjectMergeRequest | ProjectIssue):
|
597
579
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
598
580
|
manager: ProjectMergeRequestManager | ProjectIssueManager
|
599
581
|
match item:
|
@@ -631,7 +613,7 @@ class GitLabApi:
|
|
631
613
|
def remove_label(
|
632
614
|
item: ProjectMergeRequest | ProjectIssue,
|
633
615
|
label: str,
|
634
|
-
)
|
616
|
+
):
|
635
617
|
# item maybe stale, refresh it to reduce the possibility of labels overwriting
|
636
618
|
GitLabApi.refresh_labels(item)
|
637
619
|
|
@@ -646,7 +628,7 @@ class GitLabApi:
|
|
646
628
|
def remove_labels(
|
647
629
|
item: ProjectMergeRequest | ProjectIssue,
|
648
630
|
labels: Iterable[str],
|
649
|
-
)
|
631
|
+
):
|
650
632
|
# item maybe stale, refresh it to reduce the possibility of labels overwriting
|
651
633
|
GitLabApi.refresh_labels(item)
|
652
634
|
|
@@ -661,21 +643,21 @@ class GitLabApi:
|
|
661
643
|
item.save()
|
662
644
|
|
663
645
|
@staticmethod
|
664
|
-
def close(item
|
646
|
+
def close(item):
|
665
647
|
item.state_event = "close"
|
666
648
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
667
649
|
item.save()
|
668
650
|
|
669
|
-
def get_user(self, username
|
651
|
+
def get_user(self, username):
|
670
652
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
671
|
-
user =
|
672
|
-
if
|
673
|
-
logging.error(
|
674
|
-
return
|
653
|
+
user = self.gl.users.list(search=username, page=1, per_page=1)
|
654
|
+
if len(user) == 0:
|
655
|
+
logging.error(username + " user not found")
|
656
|
+
return
|
675
657
|
return user[0]
|
676
658
|
|
677
659
|
@retry()
|
678
|
-
def get_project_hooks(self, repo_url
|
660
|
+
def get_project_hooks(self, repo_url):
|
679
661
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
680
662
|
p = self.get_project(repo_url)
|
681
663
|
if p is None:
|
@@ -684,7 +666,7 @@ class GitLabApi:
|
|
684
666
|
# TODO: get_all may send multiple requests, update metrics accordingly
|
685
667
|
return p.hooks.list(per_page=100, get_all=True)
|
686
668
|
|
687
|
-
def create_project_hook(self, repo_url
|
669
|
+
def create_project_hook(self, repo_url, data):
|
688
670
|
p = self.get_project(repo_url)
|
689
671
|
if p is None:
|
690
672
|
return
|
@@ -700,13 +682,13 @@ class GitLabApi:
|
|
700
682
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
701
683
|
p.hooks.create(hook)
|
702
684
|
|
703
|
-
def get_repository_tree(self, ref
|
685
|
+
def get_repository_tree(self, ref="master"):
|
704
686
|
"""
|
705
687
|
Wrapper around Gitlab.repository_tree() with pagination enabled.
|
706
688
|
"""
|
707
689
|
return self.get_items(self.project.repository_tree, ref=ref, recursive=True)
|
708
690
|
|
709
|
-
def get_file(self, path
|
691
|
+
def get_file(self, path, ref="master"):
|
710
692
|
"""
|
711
693
|
Wrapper around Gitlab.files.get() with exception handling.
|
712
694
|
"""
|
@@ -717,7 +699,7 @@ class GitLabApi:
|
|
717
699
|
except gitlab.exceptions.GitlabGetError:
|
718
700
|
return None
|
719
701
|
|
720
|
-
def initiate_saas_bundle_repo(self, repo_url
|
702
|
+
def initiate_saas_bundle_repo(self, repo_url):
|
721
703
|
project = self.get_project(repo_url)
|
722
704
|
if project is None:
|
723
705
|
return
|
@@ -732,7 +714,7 @@ class GitLabApi:
|
|
732
714
|
self.create_branch("production", "master")
|
733
715
|
|
734
716
|
def is_last_action_by_team(
|
735
|
-
self, mr
|
717
|
+
self, mr, team_usernames: list[str], hold_labels: list[str]
|
736
718
|
) -> bool:
|
737
719
|
# what is the time of the last app-sre response?
|
738
720
|
last_action_by_team = None
|
@@ -749,10 +731,7 @@ class GitLabApi:
|
|
749
731
|
# labels
|
750
732
|
gitlab_request.labels(integration=INTEGRATION_NAME).inc()
|
751
733
|
# TODO: this may send multiple requests, update metrics accordingly
|
752
|
-
label_events =
|
753
|
-
list[ProjectMergeRequestResourceLabelEvent],
|
754
|
-
mr.resourcelabelevents.list(get_all=True),
|
755
|
-
)
|
734
|
+
label_events = mr.resourcelabelevents.list(get_all=True)
|
756
735
|
for label in reversed(label_events):
|
757
736
|
if label.action == "add" and label.label["name"] in hold_labels:
|
758
737
|
username = label.user["username"]
|
@@ -819,7 +798,7 @@ class GitLabApi:
|
|
819
798
|
return None
|
820
799
|
|
821
800
|
def last_comment(
|
822
|
-
self, mr: ProjectMergeRequest, exclude_bot
|
801
|
+
self, mr: ProjectMergeRequest, exclude_bot=True
|
823
802
|
) -> dict[str, Any] | None:
|
824
803
|
comments = self.get_merge_request_comments(mr)
|
825
804
|
comments.sort(key=itemgetter("created_at"), reverse=True)
|
reconcile/utils/mr/base.py
CHANGED
@@ -5,7 +5,7 @@ from abc import (
|
|
5
5
|
abstractmethod,
|
6
6
|
)
|
7
7
|
from collections.abc import Iterable
|
8
|
-
from typing import Any
|
8
|
+
from typing import Any
|
9
9
|
from uuid import uuid4
|
10
10
|
|
11
11
|
from gitlab.exceptions import GitlabError
|
@@ -224,11 +224,8 @@ class MergeRequestBase(ABC):
|
|
224
224
|
)
|
225
225
|
|
226
226
|
def diffs(self, gitlab_cli: GitLabApi) -> Any:
|
227
|
-
return
|
228
|
-
|
229
|
-
gitlab_cli.project.repository_compare(
|
230
|
-
from_=gitlab_cli.main_branch, to=self.branch
|
231
|
-
),
|
227
|
+
return gitlab_cli.project.repository_compare(
|
228
|
+
from_=gitlab_cli.main_branch, to=self.branch
|
232
229
|
)["diffs"]
|
233
230
|
|
234
231
|
def submit(self, cli: MRClient) -> Any | None:
|
@@ -100,10 +100,10 @@ class UpdateAccessReportBase(MergeRequestBase):
|
|
100
100
|
return new_workbook_md
|
101
101
|
|
102
102
|
def process(self, gitlab_cli: GitLabApi) -> None:
|
103
|
-
|
103
|
+
workbook_md = gitlab_cli.project.files.get(
|
104
104
|
file_path=self._workbook_file_name, ref=self.branch
|
105
105
|
)
|
106
|
-
workbook_md = self._update_workbook(
|
106
|
+
workbook_md = self._update_workbook(workbook_md.decode().decode("utf-8"))
|
107
107
|
|
108
108
|
if not self._dry_run:
|
109
109
|
logging.info(
|
reconcile/utils/vcs.py
CHANGED
@@ -222,11 +222,9 @@ class VCS:
|
|
222
222
|
if not file_path.startswith("data")
|
223
223
|
else file_path
|
224
224
|
)
|
225
|
-
return (
|
226
|
-
|
227
|
-
|
228
|
-
.decode("utf-8")
|
229
|
-
)
|
225
|
+
return self._app_interface_api.project.files.get(
|
226
|
+
file_path=file_path, ref="master"
|
227
|
+
).decode()
|
230
228
|
|
231
229
|
def get_open_app_interface_merge_requests(self) -> list[ProjectMergeRequest]:
|
232
230
|
return self._app_interface_api.get_merge_requests(state=MRState.OPENED)
|
@@ -8,8 +8,6 @@ from typing import (
|
|
8
8
|
from reconcile import queries
|
9
9
|
from reconcile.gql_definitions.vpc_peerings_validator import vpc_peerings_validator
|
10
10
|
from reconcile.gql_definitions.vpc_peerings_validator.vpc_peerings_validator import (
|
11
|
-
ClusterPeeringConnectionAccountV1,
|
12
|
-
ClusterPeeringConnectionAccountVPCMeshV1,
|
13
11
|
ClusterPeeringConnectionClusterAccepterV1,
|
14
12
|
ClusterPeeringConnectionClusterRequesterV1,
|
15
13
|
ClusterV1,
|
@@ -29,23 +27,21 @@ def validate_no_cidr_overlap(
|
|
29
27
|
|
30
28
|
for cluster in clusters:
|
31
29
|
if cluster.peering:
|
32
|
-
assert cluster.network
|
33
30
|
peerings_entries = [
|
34
31
|
{
|
35
32
|
"provider": "cluster-self-vpc",
|
36
33
|
"vpc_name": cluster.name,
|
37
|
-
"cidr_block": cluster.network.vpc,
|
34
|
+
"cidr_block": cluster.network.vpc, # type: ignore[union-attr]
|
38
35
|
},
|
39
36
|
]
|
40
37
|
for peering in cluster.peering.connections:
|
41
|
-
if
|
42
|
-
aws_account_uid = peering.account.uid
|
38
|
+
if peering.provider == "account-vpc-mesh":
|
39
|
+
aws_account_uid = peering.account.uid # type: ignore[union-attr]
|
43
40
|
settings = queries.get_secret_reader_settings()
|
44
41
|
accounts = queries.get_aws_accounts(uid=aws_account_uid)
|
45
42
|
awsapi = AWSApi(1, accounts, settings=settings, init_users=False)
|
46
|
-
|
47
|
-
|
48
|
-
)
|
43
|
+
tags = peering.tags or "{}" # type: ignore[union-attr]
|
44
|
+
mesh_results = awsapi.get_vpcs_details(accounts[0], tags)
|
49
45
|
for mesh_result in mesh_results:
|
50
46
|
vpc_peering_info = {
|
51
47
|
"provider": peering.provider,
|
@@ -53,24 +49,22 @@ def validate_no_cidr_overlap(
|
|
53
49
|
"cidr_block": mesh_result["cidr_block"],
|
54
50
|
}
|
55
51
|
peerings_entries.append(vpc_peering_info)
|
56
|
-
if
|
57
|
-
cidr_block = str(peering.vpc.cidr_block)
|
52
|
+
if peering.provider == "account-vpc":
|
53
|
+
cidr_block = str(peering.vpc.cidr_block) # type: ignore[union-attr]
|
58
54
|
vpc_peering_info = {
|
59
55
|
"provider": peering.provider,
|
60
|
-
"vpc_name": peering.vpc.name,
|
56
|
+
"vpc_name": peering.vpc.name, # type: ignore[union-attr]
|
61
57
|
"cidr_block": cidr_block,
|
62
58
|
}
|
63
59
|
peerings_entries.append(vpc_peering_info)
|
64
|
-
if
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
):
|
69
|
-
assert peering.cluster.network
|
60
|
+
if peering.provider in {
|
61
|
+
"cluster-vpc-requester",
|
62
|
+
"cluster-vpc-accepter",
|
63
|
+
}:
|
70
64
|
vpc_peering_info = {
|
71
65
|
"provider": peering.provider,
|
72
|
-
"vpc_name": peering.cluster.name,
|
73
|
-
"cidr_block": peering.cluster.network.vpc,
|
66
|
+
"vpc_name": peering.cluster.name, # type: ignore[union-attr]
|
67
|
+
"cidr_block": peering.cluster.network.vpc, # type: ignore[union-attr]
|
74
68
|
}
|
75
69
|
peerings_entries.append(vpc_peering_info)
|
76
70
|
find_overlap = find_cidr_overlap(cluster.name, peerings_entries)
|
@@ -80,7 +74,7 @@ def validate_no_cidr_overlap(
|
|
80
74
|
|
81
75
|
|
82
76
|
def find_cidr_overlap(cluster_name: str, input_list: list):
|
83
|
-
for i in range(len(input_list)):
|
77
|
+
for i in range(len(input_list)): # pylint: disable=consider-using-enumerate
|
84
78
|
compared_vpc = input_list[i]
|
85
79
|
for j in range(i + 1, len(input_list)):
|
86
80
|
comparing_vpc = input_list[j]
|