qontract-reconcile 0.9.1rc206__py3-none-any.whl → 0.9.1rc208__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.9.1rc206.dist-info → qontract_reconcile-0.9.1rc208.dist-info}/METADATA +1 -1
- {qontract_reconcile-0.9.1rc206.dist-info → qontract_reconcile-0.9.1rc208.dist-info}/RECORD +13 -13
- reconcile/gql_definitions/terraform_cloudflare_resources/terraform_cloudflare_resources.py +6 -0
- reconcile/slack_usergroups.py +20 -7
- reconcile/test/test_slack_usergroups.py +2 -2
- reconcile/test/test_utils_github_api.py +69 -14
- reconcile/test/test_utils_terrascript_cloudflare_client.py +6 -0
- reconcile/utils/github_api.py +35 -19
- reconcile/utils/gitlab_api.py +5 -0
- reconcile/utils/terrascript/cloudflare_resources.py +20 -36
- {qontract_reconcile-0.9.1rc206.dist-info → qontract_reconcile-0.9.1rc208.dist-info}/WHEEL +0 -0
- {qontract_reconcile-0.9.1rc206.dist-info → qontract_reconcile-0.9.1rc208.dist-info}/entry_points.txt +0 -0
- {qontract_reconcile-0.9.1rc206.dist-info → qontract_reconcile-0.9.1rc208.dist-info}/top_level.txt +0 -0
{qontract_reconcile-0.9.1rc206.dist-info → qontract_reconcile-0.9.1rc208.dist-info}/METADATA
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: qontract-reconcile
|
3
|
-
Version: 0.9.
|
3
|
+
Version: 0.9.1rc208
|
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
|
@@ -116,7 +116,7 @@ reconcile/sentry_helper.py,sha256=Ym-SN16ICtqTgEPh3YOHDLNMtZRQOmhFzthj9XJiBlc,22
|
|
116
116
|
reconcile/service_dependencies.py,sha256=L3GgAFGeqGxqh7_Fzt0L3geS4x2yAQz8zQ_wUiYmPXY,4654
|
117
117
|
reconcile/signalfx_endpoint_monitoring.py,sha256=D1m8iq0EAKie0OD59FOcVCtpWWZ7xlo6lwBS9urwMIk,2894
|
118
118
|
reconcile/slack_base.py,sha256=K3fSYx46G1djoPb07_C9j6ChhMCt5LgV5l6v2TFkNZk,3479
|
119
|
-
reconcile/slack_usergroups.py,sha256=
|
119
|
+
reconcile/slack_usergroups.py,sha256=I6mjJkWZZ_37TyrYg0IEOwFooMHYQiBTo3qFwKAiOyU,27275
|
120
120
|
reconcile/sql_query.py,sha256=Xbg6iqotgwwFMx5i5-dMX3L8w_HDn2XLWDkvNC1oG_A,22188
|
121
121
|
reconcile/status.py,sha256=tRYtzPFsGETOfN57rcsLIJRl7cZVFkfQXNsUtoeJ7ns,545
|
122
122
|
reconcile/template_tester.py,sha256=vZz8GM46waQUGd3OVnhW5OLTqctFMH_Hh1QXxT5hduM,2384
|
@@ -235,7 +235,7 @@ reconcile/gql_definitions/terraform_cloudflare_dns/__init__.py,sha256=47DEQpj8HB
|
|
235
235
|
reconcile/gql_definitions/terraform_cloudflare_dns/terraform_cloudflare_zones.py,sha256=RH92JBJB4HpAv2TzEzy_RVvv2yAEqTSjxa8lju_Rlso,5655
|
236
236
|
reconcile/gql_definitions/terraform_cloudflare_resources/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
237
237
|
reconcile/gql_definitions/terraform_cloudflare_resources/terraform_cloudflare_accounts.py,sha256=LDiLFs6ShmooOOXllNbFr-dN81zC8BOo_LBj4p-g_Dw,3673
|
238
|
-
reconcile/gql_definitions/terraform_cloudflare_resources/terraform_cloudflare_resources.py,sha256=
|
238
|
+
reconcile/gql_definitions/terraform_cloudflare_resources/terraform_cloudflare_resources.py,sha256=nCktp5K26yn8rl0Dywfxhhn0oiitLY3O6C4YID8w62c,11607
|
239
239
|
reconcile/gql_definitions/terraform_cloudflare_users/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
240
240
|
reconcile/gql_definitions/terraform_cloudflare_users/app_interface_setting_cloudflare_and_vault.py,sha256=OHfIzX9qAePtRwARYNERuvafwVv0Zy0YUbT83Frt3eA,1984
|
241
241
|
reconcile/gql_definitions/terraform_cloudflare_users/terraform_cloudflare_roles.py,sha256=CopEDfqnz6M-rW4kwkbFK_5FvAj7t8NzzffGZUhCTuo,4059
|
@@ -320,7 +320,7 @@ reconcile/test/test_saasherder.py,sha256=0eH84fV-FBwMWM3McFp9T4oCcXyatOVl18hZyAm
|
|
320
320
|
reconcile/test/test_saasherder_allowed_secret_paths.py,sha256=L9xoTm2BF76RfMacGgi9bHUQ9RUsobIBU83Yh47xxK8,4914
|
321
321
|
reconcile/test/test_secret_reader.py,sha256=kz7nzcPjvA08cytnvcA_PMA98AEyqJWsESkYeRn5xCk,4994
|
322
322
|
reconcile/test/test_slack_base.py,sha256=UqMjYt4hPmStJfog06qwJM_afbf-E9uzy-GX741KgTY,5058
|
323
|
-
reconcile/test/test_slack_usergroups.py,sha256=
|
323
|
+
reconcile/test/test_slack_usergroups.py,sha256=d1XP3K0SSeGcopMYPhOEm_FVev6IY71hjtJU_IPKIkI,23629
|
324
324
|
reconcile/test/test_sql_query.py,sha256=l0QyIflcErIrAwSP8kOIub0jO6oi0Ncuns5IJtnuaxM,455
|
325
325
|
reconcile/test/test_terraform_cloudflare_dns.py,sha256=RDDlcxc-nl5V4ATy0dp8Q9iIl-5edCApdpEe4a-Aueo,2696
|
326
326
|
reconcile/test/test_terraform_cloudflare_resources.py,sha256=cWNE2UIhz19rLSWdpJG8xRwuEEYoIZWEkDZY7e2QN_g,3426
|
@@ -339,7 +339,7 @@ reconcile/test/test_utils_disabled_integrations.py,sha256=CIKV51ZIzzgYjPMxCe9fxE
|
|
339
339
|
reconcile/test/test_utils_expiration.py,sha256=HHrjtLD9Wd7KSEO_4JxE5G7FlaaO0d7LTo5F3xt4KgE,2727
|
340
340
|
reconcile/test/test_utils_external_resource_spec.py,sha256=o8r0THcXZADcgM4nHUXsgbKZwlW82U0Fq0qd6Ms-hdc,10752
|
341
341
|
reconcile/test/test_utils_external_resources.py,sha256=KhY1SH3g-Z6-C1LMlL5igbvmCPH5M1Ed8umYbNzO4FE,7222
|
342
|
-
reconcile/test/test_utils_github_api.py,sha256=
|
342
|
+
reconcile/test/test_utils_github_api.py,sha256=0QUz8D5OVc7zLHq6HEGq9J42vGz27VXxx0Q80m8wphc,2178
|
343
343
|
reconcile/test/test_utils_gitlab_api.py,sha256=tuGcmsjUnRoC9O85KI_76V4Okvvkat--vm43VcTIC6M,578
|
344
344
|
reconcile/test/test_utils_gpg.py,sha256=ZkSwrrkE9gJdPEa7a3bS8D4I31sJ6Dr96ZQwzZacdh8,3953
|
345
345
|
reconcile/test/test_utils_gql.py,sha256=rur8FWMGoTVPqYWhsNVQ4Bk0zHz2e3LIwnvFiCWH7-E,3170
|
@@ -368,7 +368,7 @@ reconcile/test/test_utils_terraform.py,sha256=ER02AnPHwoV8Ry0sSe1HXvOxFv0cxcblf3
|
|
368
368
|
reconcile/test/test_utils_terraform_client.py,sha256=kKVtMerDRx9Ienw5gQt-t2UZOBefnu7VW7xuGGX0nZM,13578
|
369
369
|
reconcile/test/test_utils_terraform_config_client.py,sha256=DhONtE58zrzwcvxEKS0rv1_wN996DYcut_Yk7Y-ptaw,8298
|
370
370
|
reconcile/test/test_utils_terrascript_aws_client.py,sha256=uwfY0xQu4WHFjjVgVR4o1xOLB63NO8ZyCo1S6ma30DE,8272
|
371
|
-
reconcile/test/test_utils_terrascript_cloudflare_client.py,sha256=
|
371
|
+
reconcile/test/test_utils_terrascript_cloudflare_client.py,sha256=tmb-wdm9gi8Q8i-OptatfhRhhphpIUb1vA_lwP9C0iU,19855
|
372
372
|
reconcile/test/test_utils_terrascript_cloudflare_resources.py,sha256=h1wKs6XIGIjyBa8etuovOkQ_66DBDVUqHLOKpBfWNGQ,754
|
373
373
|
reconcile/test/test_vault_replication.py,sha256=BKDuwy9C0dsb4n8KRwfZDGlEyXCKAZMMKOU-pS4ZWu8,16865
|
374
374
|
reconcile/test/test_vault_utils.py,sha256=vbJnc89XAuE07qbTuWxHM5o9F6R9SO5aHXA38fwxT7A,1122
|
@@ -410,8 +410,8 @@ reconcile/utils/external_resource_spec.py,sha256=epSXhJU8PFmX0-YJWr4fre5mxbRDOyO
|
|
410
410
|
reconcile/utils/external_resources.py,sha256=301hqVVDt78i88VLFTkSc5mq1KvVP4OiHh_DQX-B1G8,6492
|
411
411
|
reconcile/utils/git.py,sha256=kgjN93MMB5mnkuNb1n53f5kldGGf5u0pBHj9YJbiE_c,1455
|
412
412
|
reconcile/utils/git_secrets.py,sha256=Wot8ILeTyUhyxEDr15sr1KiRNZ3YsFlr3H8bJoYt7_4,2169
|
413
|
-
reconcile/utils/github_api.py,sha256=
|
414
|
-
reconcile/utils/gitlab_api.py,sha256=
|
413
|
+
reconcile/utils/github_api.py,sha256=gkcjT3qHco001CDbcXY-yBb2MXzBjV1njRx6-HB2a_s,1901
|
414
|
+
reconcile/utils/gitlab_api.py,sha256=r0DE0uD5S7VzOirLHFxVQ-Kk9o2GZoDlBnxFZzrcxX4,24580
|
415
415
|
reconcile/utils/gpg.py,sha256=EKG7_fdMv8BMlV5yUdPiqoTx-KrzmVSEAl2sLkaKwWI,1123
|
416
416
|
reconcile/utils/gql.py,sha256=gs0prtFY_Jm_-o4Fobz4hmulW9NL6KYkcrCuyXIIn1s,11622
|
417
417
|
reconcile/utils/helm.py,sha256=3b1AwIygMQA5e_WCbXzILaqZiRrGkKPmDqir2V_T0Zw,1070
|
@@ -497,7 +497,7 @@ reconcile/utils/terraform/config.py,sha256=5UVrd563TMcvi4ooa5JvWVDW1I3bIWg484u79
|
|
497
497
|
reconcile/utils/terraform/config_client.py,sha256=t4novdX7GeYPMYms97C_BBtLmt0M8CJCmCT7QHENwxg,4687
|
498
498
|
reconcile/utils/terrascript/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
499
499
|
reconcile/utils/terrascript/cloudflare_client.py,sha256=ip8UAM7Kq25sB3WWtw3aplJAHqLhNFjFsFArYT6YrSQ,9568
|
500
|
-
reconcile/utils/terrascript/cloudflare_resources.py,sha256=
|
500
|
+
reconcile/utils/terrascript/cloudflare_resources.py,sha256=GM8nHTbqUej3mjVGrv34l9GY3cXU3fDGFN3QU9LWm7Q,13896
|
501
501
|
reconcile/utils/terrascript/models.py,sha256=x9HReI0k71MHBpRTvvmPlE0G6rri5GTzPXM9cqyTWm0,475
|
502
502
|
reconcile/utils/terrascript/resources.py,sha256=bQzglnO41KZZEIeXYgi-qlup1p8R03Qyx_V944LRPsc,1391
|
503
503
|
release/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -513,8 +513,8 @@ tools/sre_checkpoints/util.py,sha256=zEDbGr18ZeHNQwW8pUsr2JRjuXIPz--WAGJxZo9sv_Y
|
|
513
513
|
tools/test/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
514
514
|
tools/test/test_qontract_cli.py,sha256=awwTHEc2DWlykuqGIYM0WOBoSL0KRnOraCLk3C7izis,1401
|
515
515
|
tools/test/test_sre_checkpoints.py,sha256=SKqPPTl9ua0RFdSSofnoQX-JZE6dFLO3LRhfQzqtfh8,2607
|
516
|
-
qontract_reconcile-0.9.
|
517
|
-
qontract_reconcile-0.9.
|
518
|
-
qontract_reconcile-0.9.
|
519
|
-
qontract_reconcile-0.9.
|
520
|
-
qontract_reconcile-0.9.
|
516
|
+
qontract_reconcile-0.9.1rc208.dist-info/METADATA,sha256=a9IgT3fr73kk3vGi-rWRl2nJpI0bhIHCKxfcRqCkeGY,2248
|
517
|
+
qontract_reconcile-0.9.1rc208.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
|
518
|
+
qontract_reconcile-0.9.1rc208.dist-info/entry_points.txt,sha256=3BPvsRryM1C4S_mb5kXmP5AVv-wJBzVCrOJyv6qUmc0,195
|
519
|
+
qontract_reconcile-0.9.1rc208.dist-info/top_level.txt,sha256=j0CHPIc8TsVRB50wOz_jhxjjaRyCJB3NOQeXhuHS67c,34
|
520
|
+
qontract_reconcile-0.9.1rc208.dist-info/RECORD,,
|
@@ -148,6 +148,9 @@ query TerraformCloudflareResources {
|
|
148
148
|
ownership_challenge
|
149
149
|
dataset
|
150
150
|
frequency
|
151
|
+
job_name: name
|
152
|
+
filter
|
153
|
+
kind
|
151
154
|
}
|
152
155
|
... on NamespaceTerraformResourceLogpullRetention_v1
|
153
156
|
{
|
@@ -304,6 +307,9 @@ class NamespaceTerraformResourceLogpushJobV1(NamespaceTerraformResourceCloudflar
|
|
304
307
|
ownership_challenge: Optional[str] = Field(..., alias="ownership_challenge")
|
305
308
|
dataset: Optional[str] = Field(..., alias="dataset")
|
306
309
|
frequency: Optional[str] = Field(..., alias="frequency")
|
310
|
+
job_name: Optional[str] = Field(..., alias="job_name")
|
311
|
+
filter: Optional[str] = Field(..., alias="filter")
|
312
|
+
kind: Optional[str] = Field(..., alias="kind")
|
307
313
|
|
308
314
|
|
309
315
|
class NamespaceTerraformResourceLogpullRetentionV1(
|
reconcile/slack_usergroups.py
CHANGED
@@ -37,6 +37,9 @@ from reconcile.gql_definitions.slack_usergroups.users import UserV1
|
|
37
37
|
from reconcile.gql_definitions.slack_usergroups.users import query as users_query
|
38
38
|
from reconcile.openshift_base import user_has_cluster_access
|
39
39
|
from reconcile.slack_base import get_slackapi
|
40
|
+
from reconcile.typed_queries.app_interface_vault_settings import (
|
41
|
+
get_app_interface_vault_settings,
|
42
|
+
)
|
40
43
|
from reconcile.typed_queries.pagerduty_instances import get_pagerduty_instances
|
41
44
|
from reconcile.utils import gql
|
42
45
|
from reconcile.utils.disabled_integrations import integration_is_enabled
|
@@ -44,7 +47,7 @@ from reconcile.utils.exceptions import (
|
|
44
47
|
AppInterfaceSettingsError,
|
45
48
|
UnknownError,
|
46
49
|
)
|
47
|
-
from reconcile.utils.github_api import
|
50
|
+
from reconcile.utils.github_api import GithubRepositoryApi
|
48
51
|
from reconcile.utils.gitlab_api import GitLabApi
|
49
52
|
from reconcile.utils.pagerduty_api import (
|
50
53
|
PagerDutyApiException,
|
@@ -52,7 +55,10 @@ from reconcile.utils.pagerduty_api import (
|
|
52
55
|
get_pagerduty_map,
|
53
56
|
)
|
54
57
|
from reconcile.utils.repo_owners import RepoOwners
|
55
|
-
from reconcile.utils.secret_reader import
|
58
|
+
from reconcile.utils.secret_reader import (
|
59
|
+
SecretReader,
|
60
|
+
create_secret_reader,
|
61
|
+
)
|
56
62
|
from reconcile.utils.slack_api import (
|
57
63
|
SlackApi,
|
58
64
|
SlackApiError,
|
@@ -64,18 +70,25 @@ QONTRACT_INTEGRATION = "slack-usergroups"
|
|
64
70
|
error_occurred = False
|
65
71
|
|
66
72
|
|
67
|
-
def get_git_api(url: str) -> Union[
|
73
|
+
def get_git_api(url: str) -> Union[GithubRepositoryApi, GitLabApi]:
|
68
74
|
"""Return GitHub/GitLab API based on url."""
|
69
75
|
parsed_url = urlparse(url)
|
70
|
-
settings = queries.get_app_interface_settings()
|
71
76
|
|
72
77
|
if parsed_url.hostname:
|
73
78
|
if "github" in parsed_url.hostname:
|
79
|
+
vault_settings = get_app_interface_vault_settings()
|
80
|
+
secret_reader = create_secret_reader(use_vault=vault_settings.vault)
|
74
81
|
instance = queries.get_github_instance()
|
75
|
-
|
82
|
+
token = secret_reader.read(instance["token"])
|
83
|
+
|
84
|
+
return GithubRepositoryApi(
|
85
|
+
repo_url=url,
|
86
|
+
token=token,
|
87
|
+
)
|
76
88
|
if "gitlab" in parsed_url.hostname:
|
89
|
+
settings = queries.get_app_interface_settings()
|
77
90
|
instance = queries.get_gitlab_instance()
|
78
|
-
return GitLabApi(instance, project_url=url, settings=settings)
|
91
|
+
return GitLabApi(instance=instance, project_url=url, settings=settings)
|
79
92
|
|
80
93
|
raise ValueError(f"Unable to handle URL: {url}")
|
81
94
|
|
@@ -294,7 +307,7 @@ def get_slack_usernames_from_owners(
|
|
294
307
|
if isinstance(repo_cli, GitLabApi):
|
295
308
|
user_key = "org_username"
|
296
309
|
missing_user_log_method = logging.warning
|
297
|
-
elif isinstance(repo_cli,
|
310
|
+
elif isinstance(repo_cli, GithubRepositoryApi):
|
298
311
|
user_key = "github_username"
|
299
312
|
missing_user_log_method = logging.debug
|
300
313
|
else:
|
@@ -46,7 +46,7 @@ from reconcile.slack_usergroups import (
|
|
46
46
|
get_users,
|
47
47
|
)
|
48
48
|
from reconcile.utils import repo_owners
|
49
|
-
from reconcile.utils.github_api import
|
49
|
+
from reconcile.utils.github_api import GithubRepositoryApi
|
50
50
|
from reconcile.utils.pagerduty_api import PagerDutyMap
|
51
51
|
from reconcile.utils.slack_api import SlackApi
|
52
52
|
|
@@ -216,7 +216,7 @@ def test_get_usernames_from_pagerduty(user: UserV1) -> None:
|
|
216
216
|
def test_get_slack_usernames_from_owners(mocker: MockerFixture, user: UserV1) -> None:
|
217
217
|
mocker.patch(
|
218
218
|
"reconcile.slack_usergroups.get_git_api"
|
219
|
-
).return_value = create_autospec(
|
219
|
+
).return_value = create_autospec(GithubRepositoryApi)
|
220
220
|
mock_repo_owner = create_autospec(repo_owners.RepoOwners)
|
221
221
|
mock_repo_owner.return_value.get_root_owners.return_value = {
|
222
222
|
"approvers": ["approver1"],
|
@@ -1,18 +1,73 @@
|
|
1
|
-
from unittest import
|
2
|
-
|
1
|
+
from unittest.mock import (
|
2
|
+
MagicMock,
|
3
|
+
create_autospec,
|
4
|
+
)
|
3
5
|
|
4
|
-
from
|
6
|
+
from github import Github
|
7
|
+
from github.ContentFile import ContentFile
|
8
|
+
from github.Repository import Repository
|
5
9
|
|
6
|
-
from reconcile.utils.github_api import
|
10
|
+
from reconcile.utils.github_api import GithubRepositoryApi
|
7
11
|
|
8
12
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
def github(multiple_contents: bool = False):
|
14
|
+
github_mock = create_autospec(spec=Github)
|
15
|
+
repo_mock = create_autospec(spec=Repository)
|
16
|
+
get_content_mock = MagicMock()
|
17
|
+
repo_mock.get_contents = get_content_mock
|
18
|
+
content_file = create_autospec(spec=ContentFile)
|
19
|
+
content_file.decoded_content = b"test"
|
20
|
+
get_content_mock.side_effect = [content_file]
|
21
|
+
if multiple_contents:
|
22
|
+
get_content_mock.side_effect = [[content_file, content_file]]
|
23
|
+
github_mock.get_repo = MagicMock()
|
24
|
+
github_mock.get_repo.side_effect = [repo_mock]
|
25
|
+
return github_mock
|
26
|
+
|
27
|
+
|
28
|
+
def test_create():
|
29
|
+
gh = github()
|
30
|
+
GithubRepositoryApi(
|
31
|
+
repo_url="https://github.com/my/repo",
|
32
|
+
token="some-token",
|
33
|
+
github=gh,
|
34
|
+
)
|
35
|
+
gh.get_repo.assert_called_once_with("my/repo")
|
36
|
+
|
37
|
+
|
38
|
+
def test_get_file_default():
|
39
|
+
api = GithubRepositoryApi(
|
40
|
+
repo_url="https://github.com/my/repo", token="some-token", github=github()
|
41
|
+
)
|
42
|
+
content = api.get_file(path="some/path")
|
43
|
+
assert content == b"test"
|
44
|
+
api._repo.get_contents.assert_called_once_with( # type: ignore[attr-defined]
|
45
|
+
path="some/path",
|
46
|
+
ref="master",
|
47
|
+
)
|
48
|
+
|
49
|
+
|
50
|
+
def test_get_file_with_ref():
|
51
|
+
api = GithubRepositoryApi(
|
52
|
+
repo_url="https://github.com/my/repo", token="some-token", github=github()
|
53
|
+
)
|
54
|
+
content = api.get_file(path="some/path", ref="some-ref")
|
55
|
+
assert content == b"test"
|
56
|
+
api._repo.get_contents.assert_called_once_with( # type: ignore[attr-defined]
|
57
|
+
path="some/path",
|
58
|
+
ref="some-ref",
|
59
|
+
)
|
60
|
+
|
61
|
+
|
62
|
+
def test_get_file_list_returned():
|
63
|
+
api = GithubRepositoryApi(
|
64
|
+
repo_url="https://github.com/my/repo",
|
65
|
+
token="some-token",
|
66
|
+
github=github(multiple_contents=True),
|
67
|
+
)
|
68
|
+
content = api.get_file(path="some/path")
|
69
|
+
assert content is None
|
70
|
+
api._repo.get_contents.assert_called_once_with( # type: ignore[attr-defined]
|
71
|
+
path="some/path",
|
72
|
+
ref="master",
|
73
|
+
)
|
@@ -168,6 +168,7 @@ def test_create_cloudflare_resources_terraform_json(account_config, backend_conf
|
|
168
168
|
"ownership_challenge": "some-challenge",
|
169
169
|
"dataset": "http_requests",
|
170
170
|
"frequency": "high",
|
171
|
+
"kind": "edge",
|
171
172
|
},
|
172
173
|
{},
|
173
174
|
)
|
@@ -183,6 +184,8 @@ def test_create_cloudflare_resources_terraform_json(account_config, backend_conf
|
|
183
184
|
"ownership_challenge": "some-challenge",
|
184
185
|
"dataset": "http_requests",
|
185
186
|
"frequency": "high",
|
187
|
+
"job_name": "Logpush job for account",
|
188
|
+
"filter": '{"key":"BotScore","operator":"lt","value":"30"}',
|
186
189
|
},
|
187
190
|
{},
|
188
191
|
)
|
@@ -322,6 +325,7 @@ def test_create_cloudflare_resources_terraform_json(account_config, backend_conf
|
|
322
325
|
"frequency": "high",
|
323
326
|
"logpull_options": "fields=RayID,ClientIP,EdgeStartTimestamp×tamps=rfc3339",
|
324
327
|
"ownership_challenge": "some-challenge",
|
328
|
+
"kind": "edge",
|
325
329
|
},
|
326
330
|
"logpush_job_account": {
|
327
331
|
"account_id": "${var.account_id}",
|
@@ -331,6 +335,8 @@ def test_create_cloudflare_resources_terraform_json(account_config, backend_conf
|
|
331
335
|
"frequency": "high",
|
332
336
|
"logpull_options": "fields=RayID,ClientIP,EdgeStartTimestamp×tamps=rfc3339",
|
333
337
|
"ownership_challenge": "some-challenge",
|
338
|
+
"name": "Logpush job for account",
|
339
|
+
"filter": '{"key":"BotScore","operator":"lt","value":"30"}',
|
334
340
|
},
|
335
341
|
},
|
336
342
|
"cloudflare_logpull_retention": {
|
reconcile/utils/github_api.py
CHANGED
@@ -1,47 +1,63 @@
|
|
1
1
|
import os
|
2
2
|
from pathlib import Path
|
3
|
+
from typing import Optional
|
3
4
|
from urllib.parse import urlparse
|
4
5
|
|
5
|
-
import
|
6
|
+
from github import (
|
7
|
+
Github,
|
8
|
+
UnknownObjectException,
|
9
|
+
)
|
6
10
|
from sretoolbox.utils import retry
|
7
11
|
|
8
|
-
from reconcile.utils.secret_reader import SecretReader
|
9
|
-
|
10
12
|
GH_BASE_URL = os.environ.get("GITHUB_API", "https://api.github.com")
|
11
13
|
|
12
14
|
|
13
|
-
class
|
15
|
+
class GithubRepositoryApi:
|
14
16
|
"""
|
15
17
|
Github client implementing the common interfaces used in
|
16
18
|
the qontract-reconcile integrations.
|
17
19
|
|
18
|
-
:param instance: the Github instance and provided
|
19
|
-
by the app-interface
|
20
20
|
:param repo_url: the Github repository URL
|
21
|
-
:param
|
22
|
-
:type instance: dict
|
21
|
+
:param token: auth token for Github
|
23
22
|
:type repo_url: str
|
24
|
-
:type
|
23
|
+
:type token: str
|
25
24
|
"""
|
26
25
|
|
27
|
-
def __init__(
|
26
|
+
def __init__(
|
27
|
+
self,
|
28
|
+
repo_url: str,
|
29
|
+
token: str,
|
30
|
+
timeout: int = 30,
|
31
|
+
github: Optional[Github] = None,
|
32
|
+
):
|
28
33
|
parsed_repo_url = urlparse(repo_url)
|
29
34
|
repo = parsed_repo_url.path.strip("/")
|
30
|
-
secret_reader = SecretReader(settings=settings)
|
31
|
-
token = secret_reader.read(instance["token"])
|
32
|
-
git_cli = github.Github(token, base_url=GH_BASE_URL, timeout=timeout)
|
33
|
-
self.repo = git_cli.get_repo(repo)
|
34
35
|
|
35
|
-
|
36
|
+
git_cli = github
|
37
|
+
if not git_cli:
|
38
|
+
git_cli = Github(token, base_url=GH_BASE_URL, timeout=timeout)
|
39
|
+
self._repo = git_cli.get_repo(repo)
|
40
|
+
|
41
|
+
def get_repository_tree(self, ref: str = "master") -> list[dict[str, str]]:
|
36
42
|
tree_items = []
|
37
|
-
for item in self.
|
43
|
+
for item in self._repo.get_git_tree(sha=ref, recursive=True).tree:
|
38
44
|
tree_item = {"path": item.path, "name": Path(item.path).name}
|
39
45
|
tree_items.append(tree_item)
|
40
46
|
return tree_items
|
41
47
|
|
42
48
|
@retry()
|
43
|
-
def get_file(self, path, ref="master"):
|
49
|
+
def get_file(self, path: str, ref: str = "master") -> Optional[bytes]:
|
44
50
|
try:
|
45
|
-
|
46
|
-
|
51
|
+
content = self._repo.get_contents(path=path, ref=ref)
|
52
|
+
if isinstance(content, list):
|
53
|
+
# TODO: we should probably raise an exception here
|
54
|
+
# or handle this properly
|
55
|
+
# -> for now staying backwards compatible
|
56
|
+
return None
|
57
|
+
return content.decoded_content
|
58
|
+
except UnknownObjectException:
|
47
59
|
return None
|
60
|
+
|
61
|
+
@retry()
|
62
|
+
def get_commit_sha(self, ref: str) -> str:
|
63
|
+
return self._repo.get_commit(sha=ref).sha
|
reconcile/utils/gitlab_api.py
CHANGED
@@ -662,3 +662,8 @@ class GitLabApi: # pylint: disable=too-many-public-methods
|
|
662
662
|
continue
|
663
663
|
return comment
|
664
664
|
return None
|
665
|
+
|
666
|
+
def get_commit_sha(self, ref: str, repo_url: str) -> str:
|
667
|
+
project = self.gl.get_project(repo_url)
|
668
|
+
commits = project.commits.list(ref_name=ref, per_page=1)
|
669
|
+
return commits[0].id
|
@@ -27,9 +27,13 @@ from terrascript.resource import (
|
|
27
27
|
)
|
28
28
|
|
29
29
|
from reconcile import queries
|
30
|
+
from reconcile.typed_queries.app_interface_vault_settings import (
|
31
|
+
get_app_interface_vault_settings,
|
32
|
+
)
|
30
33
|
from reconcile.utils.external_resource_spec import ExternalResourceSpec
|
31
34
|
from reconcile.utils.external_resources import ResourceValueResolver
|
32
|
-
from reconcile.utils.github_api import
|
35
|
+
from reconcile.utils.github_api import GithubRepositoryApi
|
36
|
+
from reconcile.utils.secret_reader import create_secret_reader
|
33
37
|
from reconcile.utils.terraform import safe_resource_id
|
34
38
|
from reconcile.utils.terrascript.resources import TerrascriptResource
|
35
39
|
|
@@ -118,10 +122,13 @@ class CloudflareWorkerScriptTerrascriptResource(TerrascriptResource):
|
|
118
122
|
gh_repo = values["content_from_github"]["repo"]
|
119
123
|
gh_path = values["content_from_github"]["path"]
|
120
124
|
gh_ref = values["content_from_github"]["ref"]
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
+
instance = queries.get_github_instance()
|
126
|
+
vault_settings = get_app_interface_vault_settings()
|
127
|
+
secret_reader = create_secret_reader(use_vault=vault_settings.vault)
|
128
|
+
token = secret_reader.read(instance["token"])
|
129
|
+
gh = GithubRepositoryApi(
|
130
|
+
repo_url=gh_repo,
|
131
|
+
token=token,
|
125
132
|
)
|
126
133
|
content = gh.get_file(gh_path, gh_ref)
|
127
134
|
if content is None:
|
@@ -295,44 +302,21 @@ class CloudflareLogpushJob(TerrascriptResource):
|
|
295
302
|
def populate(self) -> list[Union[Resource, Output, Data]]:
|
296
303
|
resources = []
|
297
304
|
values = ResourceValueResolver(self._spec).resolve()
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
frequency = values.get("frequency")
|
304
|
-
ownership_challenge = values.get("ownership_challenge")
|
305
|
+
zone = values.pop("zone_name", None)
|
306
|
+
name = values.pop("job_name", None)
|
307
|
+
|
308
|
+
if name:
|
309
|
+
values["name"] = name
|
305
310
|
|
306
311
|
if zone:
|
307
312
|
resources.append(
|
308
313
|
self.cloudflare_zone(zone, name=zone, account_id="${var.account_id}")
|
309
314
|
)
|
310
|
-
|
311
|
-
cloudflare_logpush_job(
|
312
|
-
self._spec.identifier,
|
313
|
-
enabled=enabled,
|
314
|
-
logpull_options=logpull_options,
|
315
|
-
ownership_challenge=ownership_challenge,
|
316
|
-
dataset=dataset,
|
317
|
-
frequency=frequency,
|
318
|
-
destination_conf=destination_conf,
|
319
|
-
zone_id=f"${{data.cloudflare_zone.{zone}.id}}",
|
320
|
-
)
|
321
|
-
)
|
315
|
+
values["zone_id"] = f"${{data.cloudflare_zone.{zone}.id}}"
|
322
316
|
else:
|
323
|
-
|
324
|
-
cloudflare_logpush_job(
|
325
|
-
self._spec.identifier,
|
326
|
-
enabled=enabled,
|
327
|
-
logpull_options=logpull_options,
|
328
|
-
ownership_challenge=ownership_challenge,
|
329
|
-
dataset=dataset,
|
330
|
-
frequency=frequency,
|
331
|
-
destination_conf=destination_conf,
|
332
|
-
account_id="${var.account_id}",
|
333
|
-
)
|
334
|
-
)
|
317
|
+
values["account_id"] = "${var.account_id}"
|
335
318
|
|
319
|
+
resources.append(cloudflare_logpush_job(self._spec.identifier, **values))
|
336
320
|
return resources
|
337
321
|
|
338
322
|
|
File without changes
|
{qontract_reconcile-0.9.1rc206.dist-info → qontract_reconcile-0.9.1rc208.dist-info}/entry_points.txt
RENAMED
File without changes
|
{qontract_reconcile-0.9.1rc206.dist-info → qontract_reconcile-0.9.1rc208.dist-info}/top_level.txt
RENAMED
File without changes
|