qontract-reconcile 0.10.1rc593__py3-none-any.whl → 0.10.1rc595__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.1rc593
3
+ Version: 0.10.1rc595
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
@@ -111,7 +111,7 @@ reconcile/terraform_cloudflare_dns.py,sha256=auU4bzeLwd4S8D8oqpqJbrCUoEdELXrgi7v
111
111
  reconcile/terraform_cloudflare_resources.py,sha256=EbQQaoDnZ7brvRCpbFtwlD7KLk2hDVNcjhrJGaAywEk,15023
112
112
  reconcile/terraform_cloudflare_users.py,sha256=1EbTHwJgiPkJpMP-Ag340QNgGK3mXn3dcC3DpLakudM,13987
113
113
  reconcile/terraform_repo.py,sha256=c0GZFuY3rCm6VHjHqYbsgOHrEkRWKF_1LrMThsn2XDw,16127
114
- reconcile/terraform_resources.py,sha256=UJfygWCnLJAouAXU7EYpF-GBtqujeypMsWq04HZTE-A,18981
114
+ reconcile/terraform_resources.py,sha256=hnW_C8i8am1rAojIOyoDG2FZofeBxK3GxH1S281eSqo,19278
115
115
  reconcile/terraform_tgw_attachments.py,sha256=_g7QSHM03YZzTU7O189S4HYtUn7WmwOBq67G4AieU24,15298
116
116
  reconcile/terraform_users.py,sha256=kXRUxCUchKCP2dbXXOzctynqMii4oyCP6bYZHQTrlTg,10202
117
117
  reconcile/terraform_vpc_peerings.py,sha256=rnDH1u93OyzrBM8Hib0HwSnlxZtx4ScRQaZAcn3mx-k,25402
@@ -387,9 +387,9 @@ reconcile/templates/aws_access_key_email.j2,sha256=2MUr1ERmyISzKgHqsWYLd-1Wbl-pe
387
387
  reconcile/templates/email.yml.j2,sha256=OZgczNRgXPj2gVYTgwQyHAQrMGu7xp-e4W1rX19GcrU,690
388
388
  reconcile/templates/jira-checkpoint-missinginfo.j2,sha256=c_Vvg-lEENsB3tgxm9B6Y9igCUQhCnFDYh6xw-zcIbU,570
389
389
  reconcile/templating/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
390
- reconcile/templating/renderer.py,sha256=_C1QX9uqHuxzZJ6efL2Vdjb0Mahj1kXcfdvVB0Zh7E4,5044
391
- reconcile/templating/rendering.py,sha256=NH1w-iLhFzz5sWjOA3VTdmkIYgki1KDWH60Yg-0YZVw,4189
392
- reconcile/templating/validator.py,sha256=0bWxJOQL5UQ9iQT6XAnQuSIS5MJ7uE1Yf8yZJVy-EHo,3381
390
+ reconcile/templating/renderer.py,sha256=3wQrVFbm1gdF6Wb1NfCjaXzJ9tTIhFwZO8TlR90eUdc,5086
391
+ reconcile/templating/rendering.py,sha256=EWgtnnzjnMFxVkfL7qsvokIvoUhPnJxEr_goy5vgTMo,4526
392
+ reconcile/templating/validator.py,sha256=W64nR1eoKVDGewJ4DEX9ZiWWKjFEKg5w5Xi6lrrPBd8,3434
393
393
  reconcile/test/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
394
394
  reconcile/test/conftest.py,sha256=rQousYrxUz-EwAIbsYO6bIwR1B4CrOz9y_zaUVo2lfI,4466
395
395
  reconcile/test/fixtures.py,sha256=9SDWAUlSd1rCx7z3GhULHcpr-I6FyCsXxaFAZIqYQsQ,591
@@ -458,7 +458,7 @@ reconcile/test/test_terraform_cloudflare_dns.py,sha256=aQTXX8Vr4h9aWvJZTnpZEhMGY
458
458
  reconcile/test/test_terraform_cloudflare_resources.py,sha256=NK_uktyWihkQ3gMN4bCaKerpi43CXAVYGIKTfcz05rY,13550
459
459
  reconcile/test/test_terraform_cloudflare_users.py,sha256=RAFtMMdqZha3jNnNNsqbNQQUDSqUzdoM63rCw7fs4Fo,27456
460
460
  reconcile/test/test_terraform_repo.py,sha256=soKFJfF8tWIimDs39RQl3Hnh-Od-bR4PfnEA2s1UprM,11552
461
- reconcile/test/test_terraform_resources.py,sha256=mLXzBids3clL_P9ObMgFoXnw3IDxhF8GiVLLMhCOFH4,15101
461
+ reconcile/test/test_terraform_resources.py,sha256=VQ9nCJfEWEaO7WonUmwgLYc5Sf6ansVRDJngtkL5qLg,15268
462
462
  reconcile/test/test_terraform_tgw_attachments.py,sha256=cAq6exc-K-jtLla1CZUZQzVnBkyDnIlL7jybnddhLKc,36861
463
463
  reconcile/test/test_terraform_users.py,sha256=Xn4y6EcxnNQb6XcPoOhz_Ikxmh9Nrsu88OM1scN9hzY,5434
464
464
  reconcile/test/test_terraform_vpc_peerings.py,sha256=ubcsKh0TrUIwuI1-W3ETIgzsFvzAyeoFmEJFC-IK6JY,20538
@@ -624,7 +624,7 @@ reconcile/utils/internal_groups/models.py,sha256=jlkH_hyyyuwS0J1IpuS7W1AyQSKQ2Qp
624
624
  reconcile/utils/jinja2/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
625
625
  reconcile/utils/jinja2/extensions.py,sha256=zV_x8MhSHAynKhFnG3fULXrwsm5fUG_88IygZHSnN0o,1284
626
626
  reconcile/utils/jinja2/filters.py,sha256=_kJjdMsY3lGS5PUn4NnpXUQDNrL1IwiKsB-0MhTMGYM,4521
627
- reconcile/utils/jinja2/utils.py,sha256=LM5YsXoGS_7KUpy3nsLd0aWwl0uwhBGVvJIp6lTVN74,5812
627
+ reconcile/utils/jinja2/utils.py,sha256=1TV_BoKrCFxVPbRY4hhUmbasrPa_wm9AoabCEIOXRLg,5947
628
628
  reconcile/utils/membershipsources/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
629
629
  reconcile/utils/membershipsources/app_interface_resolver.py,sha256=IlDiRtJZ0AfAGKEawybB6SvsKbm1POTXL6fpEt699E0,1979
630
630
  reconcile/utils/membershipsources/models.py,sha256=IFu6KHFe-HUTJPiAO3fEw7i22yv4_ytgBW-h_wrO6V4,2015
@@ -693,8 +693,8 @@ tools/test/test_app_interface_metrics_exporter.py,sha256=SX7qL3D1SIRKFo95FoQztvf
693
693
  tools/test/test_qontract_cli.py,sha256=OvalpVRfY4pNmpMaWHHYqBjV68b1eGQjX8SCyTAXb1w,3501
694
694
  tools/test/test_sd_app_sre_alert_report.py,sha256=v363r9zM7__0kR5K6mvJoGFcM9BvE33fWAayrqkpojA,2116
695
695
  tools/test/test_sre_checkpoints.py,sha256=SKqPPTl9ua0RFdSSofnoQX-JZE6dFLO3LRhfQzqtfh8,2607
696
- qontract_reconcile-0.10.1rc593.dist-info/METADATA,sha256=Lfkt4RPQCrWJAcp1p0WBo6W__DgrMYySGwnLQTWNFUw,2349
697
- qontract_reconcile-0.10.1rc593.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
698
- qontract_reconcile-0.10.1rc593.dist-info/entry_points.txt,sha256=rTjAv28I_CHLM8ID3OPqMI_suoQ9s7tFbim4aYjn9kk,376
699
- qontract_reconcile-0.10.1rc593.dist-info/top_level.txt,sha256=l5ISPoXzt0SdR4jVdkfa7RPSKNc8zAHYWAnR-Dw8Ey8,24
700
- qontract_reconcile-0.10.1rc593.dist-info/RECORD,,
696
+ qontract_reconcile-0.10.1rc595.dist-info/METADATA,sha256=enf6vRlN-w4CTr8wGMuef_otPcVxb7bXKhEPFI7tdfQ,2349
697
+ qontract_reconcile-0.10.1rc595.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
698
+ qontract_reconcile-0.10.1rc595.dist-info/entry_points.txt,sha256=rTjAv28I_CHLM8ID3OPqMI_suoQ9s7tFbim4aYjn9kk,376
699
+ qontract_reconcile-0.10.1rc595.dist-info/top_level.txt,sha256=l5ISPoXzt0SdR4jVdkfa7RPSKNc8zAHYWAnR-Dw8Ey8,24
700
+ qontract_reconcile-0.10.1rc595.dist-info/RECORD,,
@@ -108,8 +108,8 @@ class TemplateRendererIntegration(QontractReconcileIntegration):
108
108
  def __init__(self, params: TemplateRendererIntegrationParams) -> None:
109
109
  super().__init__(params)
110
110
 
111
- @staticmethod
112
111
  def process_template(
112
+ self,
113
113
  template: TemplateV1,
114
114
  variables: dict,
115
115
  persistence: FilePersistence,
@@ -120,6 +120,7 @@ class TemplateRendererIntegration(QontractReconcileIntegration):
120
120
  TemplateData(
121
121
  variables=variables,
122
122
  ),
123
+ secret_reader=self.secret_reader,
123
124
  )
124
125
  target_path = r.render_target_path()
125
126
 
@@ -1,11 +1,12 @@
1
1
  from abc import ABC, abstractmethod
2
2
  from typing import Any, Optional, Protocol
3
3
 
4
- from jinja2.sandbox import SandboxedEnvironment
5
4
  from pydantic import BaseModel
6
5
  from ruamel import yaml
7
6
 
7
+ from reconcile.utils.jinja2.utils import process_jinja2_template
8
8
  from reconcile.utils.jsonpath import parse_jsonpath
9
+ from reconcile.utils.secret_reader import SecretReaderBase
9
10
 
10
11
 
11
12
  class TemplateData(BaseModel):
@@ -34,17 +35,24 @@ class Template(Protocol):
34
35
 
35
36
 
36
37
  class Renderer(ABC):
37
- def __init__(self, template: Template, data: TemplateData):
38
+ def __init__(
39
+ self,
40
+ template: Template,
41
+ data: TemplateData,
42
+ secret_reader: SecretReaderBase,
43
+ ):
38
44
  self.template = template
39
45
  self.data = data
40
- self.jinja_env = SandboxedEnvironment()
46
+ self.secret_reader = secret_reader
41
47
 
42
48
  def _jinja2_render_kwargs(self) -> dict[str, Any]:
43
49
  return {**self.data.variables, "current": self.data.current}
44
50
 
45
51
  def _render_template(self, template: str) -> str:
46
- return self.jinja_env.from_string(template).render(
47
- **self._jinja2_render_kwargs()
52
+ return process_jinja2_template(
53
+ body=template,
54
+ vars=self._jinja2_render_kwargs(),
55
+ secret_reader=self.secret_reader,
48
56
  )
49
57
 
50
58
  @abstractmethod
@@ -126,7 +134,15 @@ class PatchRenderer(Renderer):
126
134
  return yaml.dump(self.data.current, width=4096, Dumper=yaml.RoundTripDumper)
127
135
 
128
136
 
129
- def create_renderer(template: Template, data: TemplateData) -> Renderer:
137
+ def create_renderer(
138
+ template: Template,
139
+ data: TemplateData,
140
+ secret_reader: SecretReaderBase,
141
+ ) -> Renderer:
130
142
  if template.patch:
131
- return PatchRenderer(template=template, data=data)
132
- return FullRenderer(template=template, data=data)
143
+ return PatchRenderer(template=template, data=data, secret_reader=secret_reader)
144
+ return FullRenderer(
145
+ template=template,
146
+ data=data,
147
+ secret_reader=secret_reader,
148
+ )
@@ -52,7 +52,6 @@ class TemplateValidatorIntegration(QontractReconcileIntegration):
52
52
  for template in get_templates():
53
53
  for test in template.template_test:
54
54
  logging.info(f"Running test {test.name} for template {template.name}")
55
-
56
55
  r = create_renderer(
57
56
  template,
58
57
  TemplateData(
@@ -61,6 +60,7 @@ class TemplateValidatorIntegration(QontractReconcileIntegration):
61
60
  test.current or "", Loader=yaml.RoundTripLoader
62
61
  ),
63
62
  ),
63
+ secret_reader=self.secret_reader,
64
64
  )
65
65
  if test.expected_target_path:
66
66
  self.diff_result(
@@ -67,7 +67,7 @@ from reconcile.utils.vault import (
67
67
  )
68
68
 
69
69
  QONTRACT_INTEGRATION = "terraform_resources"
70
- QONTRACT_INTEGRATION_VERSION = make_semver(0, 5, 2)
70
+ QONTRACT_INTEGRATION_VERSION = make_semver(0, 5, 3)
71
71
  QONTRACT_TF_PREFIX = "qrtf"
72
72
 
73
73
 
@@ -350,6 +350,11 @@ class MultipleAccountNamesInDryRunException(Exception):
350
350
  pass
351
351
 
352
352
 
353
+ class CacheSource(TypedDict):
354
+ terraform_configurations: dict[str, str]
355
+ resource_spec_inventory: ExternalResourceSpecInventory
356
+
357
+
353
358
  @defer
354
359
  def run(
355
360
  dry_run: bool,
@@ -414,11 +419,15 @@ def run(
414
419
  "terraform-resources-extended-early-exit",
415
420
  default=False,
416
421
  ):
422
+ cache_source = CacheSource(
423
+ terraform_configurations=ts.terraform_configurations(),
424
+ resource_spec_inventory=ts.resource_spec_inventory,
425
+ )
417
426
  extended_early_exit_run(
418
427
  integration=QONTRACT_INTEGRATION,
419
428
  integration_version=QONTRACT_INTEGRATION_VERSION,
420
429
  dry_run=dry_run,
421
- cache_source=ts.terraform_configurations(),
430
+ cache_source=cache_source,
422
431
  shard="_".join(account_name) if account_name else "",
423
432
  ttl_seconds=extended_early_exit_cache_ttl_seconds,
424
433
  logger=logging.getLogger(),
@@ -370,12 +370,16 @@ def test_run_with_extended_early_exit_run_enabled(
370
370
  log_cached_log_output=True,
371
371
  defer=defer,
372
372
  )
373
+ expected_cache_source = {
374
+ "terraform_configurations": mocks["ts"].terraform_configurations.return_value,
375
+ "resource_spec_inventory": mocks["ts"].resource_spec_inventory,
376
+ }
373
377
 
374
378
  mocks["extended_early_exit_run"].assert_called_once_with(
375
379
  integration=integ.QONTRACT_INTEGRATION,
376
380
  integration_version=integ.QONTRACT_INTEGRATION_VERSION,
377
381
  dry_run=True,
378
- cache_source=mocks["ts"].terraform_configurations.return_value,
382
+ cache_source=expected_cache_source,
379
383
  shard="a",
380
384
  ttl_seconds=60,
381
385
  logger=mocks["logging"].getLogger.return_value,
@@ -157,6 +157,9 @@ def process_jinja2_template(
157
157
  "query": lookup_graphql_query_results,
158
158
  "url": url_makes_sense,
159
159
  })
160
+ if "_template_mocks" in vars:
161
+ for k, v in vars["_template_mocks"].items():
162
+ vars[k] = lambda *args, **kwargs: v
160
163
  try:
161
164
  template = compile_jinja2_template(body, extra_curly)
162
165
  r = template.render(vars)