Skip to content

Commit

Permalink
Use region when looking for a resolver being satisfied (#3490)
Browse files Browse the repository at this point in the history
* Use region when looking for a resolver being satisfied

* Update github workflows
  • Loading branch information
kddejong authored Jul 11, 2024
1 parent afcf307 commit 93b27c2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci-branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@ jobs:
ignore-vulns: |
GHSA-r9hx-vwmv-q579
PYSEC-2022-43012
PYSEC-2024-60
1 change: 1 addition & 0 deletions .github/workflows/ci-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,4 @@ jobs:
ignore-vulns: |
GHSA-r9hx-vwmv-q579
PYSEC-2022-43012
PYSEC-2024-60
2 changes: 2 additions & 0 deletions src/cfnlint/conditions/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import itertools
import logging
import traceback
from functools import lru_cache
from typing import Any, Iterator, Set, Tuple

from sympy import And, Implies, Not, Symbol
Expand Down Expand Up @@ -294,6 +295,7 @@ def check_implies(self, scenarios: dict[str, bool], implies: str) -> bool:
# formatting or just the wrong condition name
return True

@lru_cache()
def build_scenerios_on_region(
self, condition_name: str, region: str
) -> Iterator[bool]:
Expand Down
6 changes: 3 additions & 3 deletions src/cfnlint/jsonschema/_resolvers_cfn.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def ref(validator: Validator, instance: Any) -> ResolutionResult:
if not isinstance(instance, (str, dict)):
return

for instance, _, _ in validator.resolve_value(instance):
for instance, instance_validator, _ in validator.resolve_value(instance):
if validator.is_type(instance, "string"):
# if the ref is to pseudo-parameter or parameter we can validate the values
for v, c in validator.context.ref_value(instance):
yield v, validator.evolve(context=c), None
for v, c in instance_validator.context.ref_value(instance):
yield v, instance_validator.evolve(context=c), None
return


Expand Down
22 changes: 12 additions & 10 deletions src/cfnlint/jsonschema/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,23 @@ def resolve_value(self, instance: Any) -> ResolutionResult:
for r_value, r_validator, r_errs in self._resolve_fn(key, value): # type: ignore
if not r_errs:
try:
if self.cfn.conditions.satisfiable(
r_validator.context.conditions.status,
r_validator.context.ref_values,
for _, region_context in r_validator.context.ref_value(
"AWS::Region"
):
r_validator = r_validator.evolve(
context=r_validator.context.evolve(
is_resolved_value=True,
)
)
yield r_value, r_validator, r_errs
if self.cfn.conditions.satisfiable(
region_context.conditions.status,
region_context.ref_values,
):
yield r_value, r_validator.evolve(
context=region_context.evolve(
is_resolved_value=True,
)
), r_errs
except UnknownSatisfisfaction as err:
LOGGER.debug(err)
return
else:
yield None, self, r_errs # type: ignore
yield None, r_validator, r_errs # type: ignore
return

# The return type is a Protocol and we are returning an instance
Expand Down
2 changes: 1 addition & 1 deletion test/unit/module/conditions/test_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def test_check_condition_region(self):
],
)
self.assertListEqual(
list(cfn.conditions.build_scenerios_on_region({"Ref": "Foo"}, "us-east-1")),
list(cfn.conditions.build_scenerios_on_region(1, "us-east-1")),
[],
)

Expand Down

0 comments on commit 93b27c2

Please sign in to comment.