qontract-reconcile 0.10.1rc1201__py3-none-any.whl → 0.10.2.dev1__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.dev1.dist-info/METADATA +500 -0
- {qontract_reconcile-0.10.1rc1201.dist-info → qontract_reconcile-0.10.2.dev1.dist-info}/RECORD +14 -132
- {qontract_reconcile-0.10.1rc1201.dist-info → qontract_reconcile-0.10.2.dev1.dist-info}/WHEEL +1 -2
- {qontract_reconcile-0.10.1rc1201.dist-info → qontract_reconcile-0.10.2.dev1.dist-info}/entry_points.txt +1 -0
- reconcile/aws_account_manager/README.md +5 -0
- reconcile/change_owners/README.md +34 -0
- reconcile/external_resources/manager.py +12 -1
- reconcile/external_resources/model.py +11 -0
- reconcile/glitchtip/README.md +150 -0
- reconcile/gql_definitions/introspection.json +51176 -0
- reconcile/run_integration.py +293 -0
- reconcile/utils/binary.py +2 -2
- reconcile/utils/mr/README.md +198 -0
- reconcile/utils/oc_map.py +2 -2
- tools/qontract_cli.py +0 -0
- qontract_reconcile-0.10.1rc1201.dist-info/METADATA +0 -64
- qontract_reconcile-0.10.1rc1201.dist-info/top_level.txt +0 -3
- reconcile/test/__init__.py +0 -0
- reconcile/test/conftest.py +0 -157
- reconcile/test/fixtures.py +0 -24
- reconcile/test/saas_auto_promotions_manager/__init__.py +0 -0
- reconcile/test/saas_auto_promotions_manager/conftest.py +0 -170
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/__init__.py +0 -0
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/__init__.py +0 -0
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/conftest.py +0 -115
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/data_keys.py +0 -19
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_desired_state.py +0 -66
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_merge_request_manager.py +0 -86
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_mr_parser.py +0 -352
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_reconciler.py +0 -494
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/__init__.py +0 -0
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/conftest.py +0 -25
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_content_multiple_namespaces.py +0 -37
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_content_single_namespace.py +0 -81
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_content_single_target.py +0 -61
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_json_path_selector.py +0 -74
- reconcile/test/saas_auto_promotions_manager/test_integration_test.py +0 -52
- reconcile/test/saas_auto_promotions_manager/utils/__init__.py +0 -0
- reconcile/test/test_acs_notifiers.py +0 -393
- reconcile/test/test_acs_policies.py +0 -497
- reconcile/test/test_acs_rbac.py +0 -865
- reconcile/test/test_aggregated_list.py +0 -237
- reconcile/test/test_amtool.py +0 -37
- reconcile/test/test_aws_ami_cleanup.py +0 -230
- reconcile/test/test_aws_ami_share.py +0 -68
- reconcile/test/test_aws_cloudwatch_log_retention.py +0 -434
- reconcile/test/test_aws_iam_keys.py +0 -70
- reconcile/test/test_aws_iam_password_reset.py +0 -35
- reconcile/test/test_aws_support_cases_sos.py +0 -23
- reconcile/test/test_checkpoint.py +0 -178
- reconcile/test/test_cli.py +0 -41
- reconcile/test/test_closedbox_endpoint_monitoring.py +0 -207
- reconcile/test/test_dashdotdb_dora.py +0 -245
- reconcile/test/test_database_access_manager.py +0 -660
- reconcile/test/test_deadmanssnitch.py +0 -290
- reconcile/test/test_gabi_authorized_users.py +0 -72
- reconcile/test/test_gcr_mirror.py +0 -14
- reconcile/test/test_github_org.py +0 -156
- reconcile/test/test_github_repo_invites.py +0 -119
- reconcile/test/test_gitlab_housekeeping.py +0 -333
- reconcile/test/test_gitlab_labeler.py +0 -126
- reconcile/test/test_gitlab_members.py +0 -219
- reconcile/test/test_gitlab_permissions.py +0 -164
- reconcile/test/test_instrumented_wrappers.py +0 -18
- reconcile/test/test_integrations_manager.py +0 -1252
- reconcile/test/test_jenkins_worker_fleets.py +0 -57
- reconcile/test/test_jira_permissions_validator.py +0 -519
- reconcile/test/test_jump_host.py +0 -114
- reconcile/test/test_ldap_users.py +0 -125
- reconcile/test/test_make.py +0 -28
- reconcile/test/test_ocm_additional_routers.py +0 -133
- reconcile/test/test_ocm_clusters.py +0 -798
- reconcile/test/test_ocm_clusters_manifest_updates.py +0 -87
- reconcile/test/test_ocm_machine_pools.py +0 -1103
- reconcile/test/test_ocm_update_recommended_version.py +0 -145
- reconcile/test/test_ocm_upgrade_scheduler_org_updater.py +0 -125
- reconcile/test/test_openshift_base.py +0 -1269
- reconcile/test/test_openshift_cluster_bots.py +0 -240
- reconcile/test/test_openshift_namespace_labels.py +0 -344
- reconcile/test/test_openshift_namespaces.py +0 -256
- reconcile/test/test_openshift_resource.py +0 -443
- reconcile/test/test_openshift_resources_base.py +0 -478
- reconcile/test/test_openshift_saas_deploy.py +0 -188
- reconcile/test/test_openshift_saas_deploy_change_tester.py +0 -308
- reconcile/test/test_openshift_saas_deploy_trigger_cleaner.py +0 -65
- reconcile/test/test_openshift_serviceaccount_tokens.py +0 -282
- reconcile/test/test_openshift_tekton_resources.py +0 -265
- reconcile/test/test_openshift_upgrade_watcher.py +0 -223
- reconcile/test/test_prometheus_rules_tester.py +0 -151
- reconcile/test/test_quay_membership.py +0 -86
- reconcile/test/test_quay_mirror.py +0 -172
- reconcile/test/test_quay_mirror_org.py +0 -82
- reconcile/test/test_quay_repos.py +0 -59
- reconcile/test/test_queries.py +0 -53
- reconcile/test/test_repo_owners.py +0 -47
- reconcile/test/test_requests_sender.py +0 -139
- reconcile/test/test_saasherder.py +0 -1611
- reconcile/test/test_saasherder_allowed_secret_paths.py +0 -125
- reconcile/test/test_secret_reader.py +0 -153
- reconcile/test/test_slack_base.py +0 -183
- reconcile/test/test_slack_usergroups.py +0 -785
- reconcile/test/test_sql_query.py +0 -316
- reconcile/test/test_status_board.py +0 -258
- reconcile/test/test_terraform_aws_route53.py +0 -29
- reconcile/test/test_terraform_cloudflare_dns.py +0 -117
- reconcile/test/test_terraform_cloudflare_resources.py +0 -408
- reconcile/test/test_terraform_cloudflare_users.py +0 -747
- reconcile/test/test_terraform_repo.py +0 -440
- reconcile/test/test_terraform_resources.py +0 -519
- reconcile/test/test_terraform_tgw_attachments.py +0 -1295
- reconcile/test/test_terraform_users.py +0 -152
- reconcile/test/test_terraform_vpc_peerings.py +0 -576
- reconcile/test/test_terraform_vpc_peerings_build_desired_state.py +0 -1434
- reconcile/test/test_three_way_diff_strategy.py +0 -131
- reconcile/test/test_utils_jinja2.py +0 -130
- reconcile/test/test_vault_replication.py +0 -534
- reconcile/test/test_vault_utils.py +0 -47
- reconcile/test/test_version_bump.py +0 -18
- reconcile/test/test_vpc_peerings_validator.py +0 -194
- reconcile/test/test_wrong_region.py +0 -78
- release/__init__.py +0 -0
- release/test_version.py +0 -50
- release/version.py +0 -104
- tools/cli_commands/test/__init__.py +0 -0
- tools/cli_commands/test/conftest.py +0 -332
- tools/cli_commands/test/test_aws_cost_report.py +0 -258
- tools/cli_commands/test/test_cost_management_api.py +0 -326
- tools/cli_commands/test/test_gpg_encrypt.py +0 -235
- tools/cli_commands/test/test_openshift_cost_optimization_report.py +0 -255
- tools/cli_commands/test/test_openshift_cost_report.py +0 -295
- tools/cli_commands/test/test_util.py +0 -70
- tools/test/__init__.py +0 -0
- tools/test/conftest.py +0 -77
- tools/test/test_app_interface_metrics_exporter.py +0 -48
- tools/test/test_erv2.py +0 -80
- tools/test/test_get_container_images.py +0 -230
- tools/test/test_qontract_cli.py +0 -197
- tools/test/test_saas_promotion_state.py +0 -187
- tools/test/test_sd_app_sre_alert_report.py +0 -74
- tools/test/test_sre_checkpoints.py +0 -79
@@ -1,497 +0,0 @@
|
|
1
|
-
import copy
|
2
|
-
from typing import Any
|
3
|
-
from unittest.mock import Mock
|
4
|
-
|
5
|
-
import pytest
|
6
|
-
from pytest_mock import MockerFixture
|
7
|
-
|
8
|
-
from reconcile.acs_policies import AcsPoliciesIntegration
|
9
|
-
from reconcile.gql_definitions.acs.acs_policies import (
|
10
|
-
AcsPolicyConditionsCveV1,
|
11
|
-
AcsPolicyConditionsCvssV1,
|
12
|
-
AcsPolicyConditionsSeverityV1,
|
13
|
-
AcsPolicyIntegrationNotifierJiraV1,
|
14
|
-
AcsPolicyIntegrationNotifiersV1,
|
15
|
-
AcsPolicyIntegrationsV1,
|
16
|
-
AcsPolicyQueryData,
|
17
|
-
AcsPolicyScopeClusterV1,
|
18
|
-
AcsPolicyScopeNamespaceV1,
|
19
|
-
AcsPolicyV1,
|
20
|
-
AppEscalationPolicyChannelsV1,
|
21
|
-
AppEscalationPolicyV1,
|
22
|
-
ClusterV1,
|
23
|
-
DisableJiraBoardAutomationsV1,
|
24
|
-
JiraBoardV1,
|
25
|
-
JiraServerV1,
|
26
|
-
JiraSeverityPriorityMappingsV1,
|
27
|
-
NamespaceV1,
|
28
|
-
NamespaceV1_ClusterV1,
|
29
|
-
)
|
30
|
-
from reconcile.utils.acs.policies import AcsPolicyApi, Policy, PolicyCondition, Scope
|
31
|
-
|
32
|
-
CLUSTER_NAME_ONE = "app-sre-stage"
|
33
|
-
CLUSTER_ID_ONE = "5211d395-5cf7-4185-a1fb-d88f41bc7542"
|
34
|
-
CLUSTER_NAME_TWO = "app-sre-prod"
|
35
|
-
CLUSTER_ID_TWO = "a217cca7-d85a-4be1-9703-f58866fdbe2d"
|
36
|
-
CUSTOM_POLICY_ONE_NAME = "app-sre-clusters-fixable-cve-7-fixable"
|
37
|
-
CUSTOM_POLICY_ONE_ID = "365d4e71-3241-4448-9f3d-eb0eed1c1820"
|
38
|
-
CUSTOM_POLICY_TWO_NAME = "app-sre-namespaces-severity-critical"
|
39
|
-
CUSTOM_POLICY_TWO_ID = "2200245e-b700-46c2-8793-3e437fca6aa0"
|
40
|
-
JIRA_NOTIFIER_NAME = "jira-test-ep"
|
41
|
-
JIRA_NOTIFIER_ID = "54170627-da34-40cb-839a-af9fbeac10fb"
|
42
|
-
|
43
|
-
|
44
|
-
@pytest.fixture
|
45
|
-
def query_data_desired_state() -> AcsPolicyQueryData:
|
46
|
-
return AcsPolicyQueryData(
|
47
|
-
acs_policies=[
|
48
|
-
AcsPolicyV1(
|
49
|
-
name=CUSTOM_POLICY_ONE_NAME,
|
50
|
-
description="CVEs within app-sre clusters with CVSS score gte to 7 and fixable",
|
51
|
-
severity="high",
|
52
|
-
integrations=AcsPolicyIntegrationsV1(
|
53
|
-
notifiers=AcsPolicyIntegrationNotifiersV1(
|
54
|
-
jira=AcsPolicyIntegrationNotifierJiraV1(
|
55
|
-
escalationPolicy=AppEscalationPolicyV1(
|
56
|
-
name=JIRA_NOTIFIER_NAME.replace("jira-", ""),
|
57
|
-
channels=AppEscalationPolicyChannelsV1(
|
58
|
-
jiraBoard=[
|
59
|
-
JiraBoardV1(
|
60
|
-
name="board",
|
61
|
-
server=JiraServerV1(
|
62
|
-
serverUrl="server",
|
63
|
-
),
|
64
|
-
severityPriorityMappings=JiraSeverityPriorityMappingsV1(
|
65
|
-
name="sp",
|
66
|
-
mappings=[],
|
67
|
-
),
|
68
|
-
issueType="Task",
|
69
|
-
issueSecurityId="0",
|
70
|
-
disable=DisableJiraBoardAutomationsV1(
|
71
|
-
integrations=[]
|
72
|
-
),
|
73
|
-
)
|
74
|
-
],
|
75
|
-
jiraComponent="",
|
76
|
-
jiraLabels=[],
|
77
|
-
),
|
78
|
-
),
|
79
|
-
),
|
80
|
-
),
|
81
|
-
),
|
82
|
-
categories=["vulnerability-management"],
|
83
|
-
scope=AcsPolicyScopeClusterV1(
|
84
|
-
level="cluster",
|
85
|
-
clusters=[
|
86
|
-
ClusterV1(name=CLUSTER_NAME_ONE),
|
87
|
-
ClusterV1(name=CLUSTER_NAME_TWO),
|
88
|
-
],
|
89
|
-
),
|
90
|
-
conditions=[
|
91
|
-
AcsPolicyConditionsCvssV1(
|
92
|
-
policyField="cvss", comparison="gte", score=7
|
93
|
-
),
|
94
|
-
AcsPolicyConditionsCveV1(policyField="cve", fixable=True),
|
95
|
-
],
|
96
|
-
),
|
97
|
-
AcsPolicyV1(
|
98
|
-
name=CUSTOM_POLICY_TWO_NAME,
|
99
|
-
description="image security policy violations of critical severity within app-sre namespaces",
|
100
|
-
severity="critical",
|
101
|
-
integrations=None,
|
102
|
-
categories=["vulnerability-management", "devops-best-practices"],
|
103
|
-
scope=AcsPolicyScopeNamespaceV1(
|
104
|
-
level="namespace",
|
105
|
-
namespaces=[
|
106
|
-
NamespaceV1(
|
107
|
-
name="app-interface-stage",
|
108
|
-
cluster=NamespaceV1_ClusterV1(name="app-sre-stage"),
|
109
|
-
),
|
110
|
-
NamespaceV1(
|
111
|
-
name="app-interface-production",
|
112
|
-
cluster=NamespaceV1_ClusterV1(name="app-sre-prod"),
|
113
|
-
),
|
114
|
-
],
|
115
|
-
),
|
116
|
-
conditions=[
|
117
|
-
AcsPolicyConditionsSeverityV1(
|
118
|
-
policyField="severity", comparison="eq", level="critical"
|
119
|
-
)
|
120
|
-
],
|
121
|
-
),
|
122
|
-
]
|
123
|
-
)
|
124
|
-
|
125
|
-
|
126
|
-
@pytest.fixture
|
127
|
-
def modeled_acs_policies() -> list[Policy]:
|
128
|
-
return [
|
129
|
-
Policy(
|
130
|
-
name=CUSTOM_POLICY_ONE_NAME,
|
131
|
-
description="CVEs within app-sre clusters with CVSS score gte to 7 and fixable",
|
132
|
-
severity="HIGH_SEVERITY",
|
133
|
-
notifiers=[JIRA_NOTIFIER_ID],
|
134
|
-
categories=["Vulnerability Management"],
|
135
|
-
scope=[
|
136
|
-
Scope(cluster=CLUSTER_ID_ONE, namespace=""),
|
137
|
-
Scope(cluster=CLUSTER_ID_TWO, namespace=""),
|
138
|
-
],
|
139
|
-
conditions=[
|
140
|
-
PolicyCondition(field_name="CVSS", values=[">=7"], negate=False),
|
141
|
-
PolicyCondition(field_name="Fixable", values=["true"], negate=False),
|
142
|
-
],
|
143
|
-
),
|
144
|
-
Policy(
|
145
|
-
name=CUSTOM_POLICY_TWO_NAME,
|
146
|
-
description="image security policy violations of critical severity within app-sre namespaces",
|
147
|
-
severity="CRITICAL_SEVERITY",
|
148
|
-
notifiers=[],
|
149
|
-
categories=["DevOps Best Practices", "Vulnerability Management"],
|
150
|
-
scope=[
|
151
|
-
Scope(cluster=CLUSTER_ID_ONE, namespace="app-interface-stage"),
|
152
|
-
Scope(cluster=CLUSTER_ID_TWO, namespace="app-interface-production"),
|
153
|
-
],
|
154
|
-
conditions=[
|
155
|
-
PolicyCondition(
|
156
|
-
field_name="Severity", values=["CRITICAL"], negate=False
|
157
|
-
)
|
158
|
-
],
|
159
|
-
),
|
160
|
-
]
|
161
|
-
|
162
|
-
|
163
|
-
@pytest.fixture
|
164
|
-
def api_response_policies_summary() -> Any:
|
165
|
-
return {
|
166
|
-
"policies": [
|
167
|
-
{
|
168
|
-
"id": CUSTOM_POLICY_ONE_ID,
|
169
|
-
"name": CUSTOM_POLICY_ONE_NAME,
|
170
|
-
"description": "CVEs within app-sre clusters with CVSS score gte to 7 and fixable",
|
171
|
-
"severity": "HIGH_SEVERITY",
|
172
|
-
"notifiers": [JIRA_NOTIFIER_ID],
|
173
|
-
"disabled": False,
|
174
|
-
"lifecycleStages": ["BUILD", "DEPLOY"],
|
175
|
-
"lastUpdated": None,
|
176
|
-
"eventSource": "NOT_APPLICABLE",
|
177
|
-
"isDefault": False,
|
178
|
-
},
|
179
|
-
{
|
180
|
-
"id": CUSTOM_POLICY_TWO_ID,
|
181
|
-
"name": CUSTOM_POLICY_TWO_NAME,
|
182
|
-
"description": "image security policy violations of critical severity within app-sre namespaces",
|
183
|
-
"severity": "CRITICAL_SEVERITY",
|
184
|
-
"disabled": False,
|
185
|
-
"lifecycleStages": ["BUILD", "DEPLOY"],
|
186
|
-
"notifiers": [],
|
187
|
-
"lastUpdated": None,
|
188
|
-
"eventSource": "NOT_APPLICABLE",
|
189
|
-
"isDefault": False,
|
190
|
-
},
|
191
|
-
{
|
192
|
-
"id": "1111245e-7700-46c2-8793-3e437fca6aa0",
|
193
|
-
"name": "some-default-policy",
|
194
|
-
"description": "default policy that should not be included in reconcile",
|
195
|
-
"severity": "CRITICAL_SEVERITY",
|
196
|
-
"disabled": False,
|
197
|
-
"lifecycleStages": ["BUILD", "DEPLOY"],
|
198
|
-
"notifiers": [],
|
199
|
-
"lastUpdated": None,
|
200
|
-
"eventSource": "NOT_APPLICABLE",
|
201
|
-
"isDefault": True,
|
202
|
-
},
|
203
|
-
]
|
204
|
-
}
|
205
|
-
|
206
|
-
|
207
|
-
@pytest.fixture
|
208
|
-
def api_response_policies_specific() -> list[Any]:
|
209
|
-
return [
|
210
|
-
{
|
211
|
-
"id": CUSTOM_POLICY_ONE_ID,
|
212
|
-
"name": CUSTOM_POLICY_ONE_NAME,
|
213
|
-
"description": "CVEs within app-sre clusters with CVSS score gte to 7 and fixable",
|
214
|
-
"disabled": False,
|
215
|
-
"categories": ["Vulnerability Management"],
|
216
|
-
"lifecycleStages": ["BUILD", "DEPLOY"],
|
217
|
-
"eventSource": "NOT_APPLICABLE",
|
218
|
-
"exclusions": [],
|
219
|
-
"scope": [
|
220
|
-
{"cluster": CLUSTER_ID_ONE, "namespace": "", "label": None},
|
221
|
-
{"cluster": CLUSTER_ID_TWO, "namespace": "", "label": None},
|
222
|
-
],
|
223
|
-
"severity": "HIGH_SEVERITY",
|
224
|
-
"enforcementActions": [],
|
225
|
-
"notifiers": [JIRA_NOTIFIER_ID],
|
226
|
-
"policySections": [
|
227
|
-
{
|
228
|
-
"sectionName": "primary",
|
229
|
-
"policyGroups": [
|
230
|
-
{
|
231
|
-
"fieldName": "CVSS",
|
232
|
-
"booleanOperator": "OR",
|
233
|
-
"negate": False,
|
234
|
-
"values": [{"value": ">=7"}],
|
235
|
-
},
|
236
|
-
{
|
237
|
-
"fieldName": "Fixable",
|
238
|
-
"booleanOperator": "OR",
|
239
|
-
"negate": False,
|
240
|
-
"values": [{"value": "true"}],
|
241
|
-
},
|
242
|
-
],
|
243
|
-
}
|
244
|
-
],
|
245
|
-
"mitreAttackVectors": [],
|
246
|
-
"criteriaLocked": False,
|
247
|
-
"mitreVectorsLocked": False,
|
248
|
-
"isDefault": False,
|
249
|
-
},
|
250
|
-
{
|
251
|
-
"id": CUSTOM_POLICY_TWO_ID,
|
252
|
-
"name": CUSTOM_POLICY_TWO_NAME,
|
253
|
-
"description": "image security policy violations of critical severity within app-sre namespaces",
|
254
|
-
"disabled": False,
|
255
|
-
"categories": ["Vulnerability Management", "DevOps Best Practices"],
|
256
|
-
"lifecycleStages": ["BUILD", "DEPLOY"],
|
257
|
-
"eventSource": "NOT_APPLICABLE",
|
258
|
-
"exclusions": [],
|
259
|
-
"scope": [
|
260
|
-
{
|
261
|
-
"cluster": CLUSTER_ID_ONE,
|
262
|
-
"namespace": "app-interface-stage",
|
263
|
-
"label": None,
|
264
|
-
},
|
265
|
-
{
|
266
|
-
"cluster": CLUSTER_ID_TWO,
|
267
|
-
"namespace": "app-interface-production",
|
268
|
-
"label": None,
|
269
|
-
},
|
270
|
-
],
|
271
|
-
"severity": "CRITICAL_SEVERITY",
|
272
|
-
"enforcementActions": [],
|
273
|
-
"notifiers": [],
|
274
|
-
"policySections": [
|
275
|
-
{
|
276
|
-
"sectionName": "primary",
|
277
|
-
"policyGroups": [
|
278
|
-
{
|
279
|
-
"fieldName": "Severity",
|
280
|
-
"booleanOperator": "OR",
|
281
|
-
"negate": False,
|
282
|
-
"values": [{"value": "CRITICAL"}],
|
283
|
-
}
|
284
|
-
],
|
285
|
-
}
|
286
|
-
],
|
287
|
-
"mitreAttackVectors": [],
|
288
|
-
"criteriaLocked": False,
|
289
|
-
"mitreVectorsLocked": False,
|
290
|
-
"isDefault": False,
|
291
|
-
},
|
292
|
-
]
|
293
|
-
|
294
|
-
|
295
|
-
@pytest.fixture
|
296
|
-
def api_response_list_notifiers() -> list[AcsPolicyApi.NotifierIdentifiers]:
|
297
|
-
return [
|
298
|
-
AcsPolicyApi.NotifierIdentifiers(id=JIRA_NOTIFIER_ID, name=JIRA_NOTIFIER_NAME)
|
299
|
-
]
|
300
|
-
|
301
|
-
|
302
|
-
@pytest.fixture
|
303
|
-
def api_response_list_clusters() -> list[AcsPolicyApi.ClusterIdentifiers]:
|
304
|
-
return [
|
305
|
-
AcsPolicyApi.ClusterIdentifiers(id=CLUSTER_ID_ONE, name=CLUSTER_NAME_ONE),
|
306
|
-
AcsPolicyApi.ClusterIdentifiers(id=CLUSTER_ID_TWO, name=CLUSTER_NAME_TWO),
|
307
|
-
]
|
308
|
-
|
309
|
-
|
310
|
-
def test_get_desired_state(
|
311
|
-
mocker: MockerFixture,
|
312
|
-
query_data_desired_state: AcsPolicyQueryData,
|
313
|
-
modeled_acs_policies: list[Policy],
|
314
|
-
api_response_list_notifiers: list[AcsPolicyApi.NotifierIdentifiers],
|
315
|
-
api_response_list_clusters: list[AcsPolicyApi.ClusterIdentifiers],
|
316
|
-
) -> None:
|
317
|
-
query_func = mocker.patch(
|
318
|
-
"reconcile.gql_definitions.acs.acs_policies.query", autospec=True
|
319
|
-
)
|
320
|
-
query_func.return_value = query_data_desired_state
|
321
|
-
|
322
|
-
integration = AcsPoliciesIntegration()
|
323
|
-
result = integration.get_desired_state(
|
324
|
-
query_func=query_func,
|
325
|
-
notifiers=api_response_list_notifiers,
|
326
|
-
clusters=api_response_list_clusters,
|
327
|
-
)
|
328
|
-
assert result == modeled_acs_policies
|
329
|
-
|
330
|
-
|
331
|
-
def test_get_current_state(
|
332
|
-
mocker: MockerFixture,
|
333
|
-
modeled_acs_policies: list[Policy],
|
334
|
-
api_response_policies_summary: list[Any],
|
335
|
-
api_response_policies_specific: list[Any],
|
336
|
-
) -> None:
|
337
|
-
list_custom_policies = Mock()
|
338
|
-
list_custom_policies.json.return_value = api_response_policies_summary
|
339
|
-
specific_custom_policy_1 = Mock()
|
340
|
-
specific_custom_policy_1.json.return_value = api_response_policies_specific[0]
|
341
|
-
specific_custom_policy_2 = Mock()
|
342
|
-
specific_custom_policy_2.json.return_value = api_response_policies_specific[1]
|
343
|
-
mocker.patch.object(
|
344
|
-
AcsPolicyApi,
|
345
|
-
"generic_request",
|
346
|
-
side_effect=[
|
347
|
-
list_custom_policies,
|
348
|
-
specific_custom_policy_1,
|
349
|
-
specific_custom_policy_2,
|
350
|
-
],
|
351
|
-
)
|
352
|
-
with AcsPolicyApi(url="foo", token="bar") as acs:
|
353
|
-
assert sorted(acs.get_custom_policies(), key=lambda p: p.name) == sorted(
|
354
|
-
modeled_acs_policies, key=lambda p: p.name
|
355
|
-
)
|
356
|
-
|
357
|
-
|
358
|
-
def test_create_policy(
|
359
|
-
mocker: MockerFixture, modeled_acs_policies: list[Policy]
|
360
|
-
) -> None:
|
361
|
-
dry_run = False
|
362
|
-
desired = modeled_acs_policies
|
363
|
-
current = modeled_acs_policies[:-1]
|
364
|
-
|
365
|
-
acs_mock = Mock()
|
366
|
-
mocker.patch.object(acs_mock, "create_or_update_policy")
|
367
|
-
|
368
|
-
integration = AcsPoliciesIntegration()
|
369
|
-
integration.reconcile(
|
370
|
-
desired=desired, current=current, acs=acs_mock, dry_run=dry_run
|
371
|
-
)
|
372
|
-
|
373
|
-
acs_mock.create_or_update_policy.assert_has_calls([
|
374
|
-
mocker.call(desired=modeled_acs_policies[1])
|
375
|
-
])
|
376
|
-
|
377
|
-
|
378
|
-
def test_create_policy_dry_run(
|
379
|
-
mocker: MockerFixture, modeled_acs_policies: list[Policy]
|
380
|
-
) -> None:
|
381
|
-
dry_run = True
|
382
|
-
desired = modeled_acs_policies
|
383
|
-
current = modeled_acs_policies[:-1]
|
384
|
-
|
385
|
-
acs_mock = Mock()
|
386
|
-
mocker.patch.object(acs_mock, "create_or_update_policy")
|
387
|
-
|
388
|
-
integration = AcsPoliciesIntegration()
|
389
|
-
integration.reconcile(
|
390
|
-
desired=desired, current=current, acs=acs_mock, dry_run=dry_run
|
391
|
-
)
|
392
|
-
|
393
|
-
acs_mock.create_or_update_policy.assert_not_called()
|
394
|
-
|
395
|
-
|
396
|
-
def test_delete_policy(
|
397
|
-
mocker: MockerFixture,
|
398
|
-
modeled_acs_policies: list[Policy],
|
399
|
-
api_response_policies_summary: Any,
|
400
|
-
) -> None:
|
401
|
-
dry_run = False
|
402
|
-
desired = modeled_acs_policies[:-1]
|
403
|
-
current = modeled_acs_policies
|
404
|
-
|
405
|
-
acs_mock = Mock()
|
406
|
-
mocker.patch.object(acs_mock, "delete_policy")
|
407
|
-
mocker.patch.object(
|
408
|
-
acs_mock,
|
409
|
-
"list_custom_policies",
|
410
|
-
return_value=api_response_policies_summary["policies"][:-1],
|
411
|
-
)
|
412
|
-
|
413
|
-
integration = AcsPoliciesIntegration()
|
414
|
-
integration.reconcile(
|
415
|
-
desired=desired, current=current, acs=acs_mock, dry_run=dry_run
|
416
|
-
)
|
417
|
-
|
418
|
-
acs_mock.delete_policy.assert_has_calls([mocker.call(CUSTOM_POLICY_TWO_ID)])
|
419
|
-
|
420
|
-
|
421
|
-
def test_delete_policy_dry_run(
|
422
|
-
mocker: MockerFixture,
|
423
|
-
modeled_acs_policies: list[Policy],
|
424
|
-
api_response_policies_summary: Any,
|
425
|
-
) -> None:
|
426
|
-
dry_run = True
|
427
|
-
desired = modeled_acs_policies[:-1]
|
428
|
-
current = modeled_acs_policies
|
429
|
-
|
430
|
-
acs_mock = Mock()
|
431
|
-
mocker.patch.object(acs_mock, "delete_policy")
|
432
|
-
mocker.patch.object(
|
433
|
-
acs_mock,
|
434
|
-
"list_custom_policies",
|
435
|
-
return_value=api_response_policies_summary["policies"][:-1],
|
436
|
-
)
|
437
|
-
|
438
|
-
integration = AcsPoliciesIntegration()
|
439
|
-
integration.reconcile(
|
440
|
-
desired=desired, current=current, acs=acs_mock, dry_run=dry_run
|
441
|
-
)
|
442
|
-
|
443
|
-
acs_mock.delete_policy.assert_not_called()
|
444
|
-
|
445
|
-
|
446
|
-
def test_update_policy(
|
447
|
-
mocker: MockerFixture,
|
448
|
-
modeled_acs_policies: list[Policy],
|
449
|
-
api_response_policies_summary: Any,
|
450
|
-
) -> None:
|
451
|
-
dry_run = False
|
452
|
-
desired = modeled_acs_policies
|
453
|
-
current = copy.deepcopy(modeled_acs_policies)
|
454
|
-
current[0].severity = "LOW_SEVERITY"
|
455
|
-
|
456
|
-
acs_mock = Mock()
|
457
|
-
mocker.patch.object(acs_mock, "create_or_update_policy")
|
458
|
-
mocker.patch.object(
|
459
|
-
acs_mock,
|
460
|
-
"list_custom_policies",
|
461
|
-
return_value=api_response_policies_summary["policies"],
|
462
|
-
)
|
463
|
-
|
464
|
-
integration = AcsPoliciesIntegration()
|
465
|
-
integration.reconcile(
|
466
|
-
desired=desired, current=current, acs=acs_mock, dry_run=dry_run
|
467
|
-
)
|
468
|
-
|
469
|
-
acs_mock.create_or_update_policy.assert_has_calls([
|
470
|
-
mocker.call(desired=desired[0], id=CUSTOM_POLICY_ONE_ID)
|
471
|
-
])
|
472
|
-
|
473
|
-
|
474
|
-
def test_update_policy_dry_run(
|
475
|
-
mocker: MockerFixture,
|
476
|
-
modeled_acs_policies: list[Policy],
|
477
|
-
api_response_policies_summary: Any,
|
478
|
-
) -> None:
|
479
|
-
dry_run = True
|
480
|
-
desired = modeled_acs_policies
|
481
|
-
current = copy.deepcopy(modeled_acs_policies)
|
482
|
-
current[0].severity = "LOW_SEVERITY"
|
483
|
-
|
484
|
-
acs_mock = Mock()
|
485
|
-
mocker.patch.object(acs_mock, "create_or_update_policy")
|
486
|
-
mocker.patch.object(
|
487
|
-
acs_mock,
|
488
|
-
"list_custom_policies",
|
489
|
-
return_value=api_response_policies_summary["policies"],
|
490
|
-
)
|
491
|
-
|
492
|
-
integration = AcsPoliciesIntegration()
|
493
|
-
integration.reconcile(
|
494
|
-
desired=desired, current=current, acs=acs_mock, dry_run=dry_run
|
495
|
-
)
|
496
|
-
|
497
|
-
acs_mock.create_or_update_policy.assert_not_called()
|