Skip to content

Commit

Permalink
Fixed #600 Assert against non-sensible excluded_accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Moy committed Aug 21, 2023
1 parent caca8d5 commit b94169f
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion iambic/core/template_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import xxhash

from iambic.core import noq_json as json
from iambic.core.iambic_enum import IambicManaged
from iambic.core.context import ctx
from iambic.core.iambic_enum import Command, IambicManaged
from iambic.core.logger import log
from iambic.core.models import AccessModelMixin, BaseModel, BaseTemplate, ProviderChild
from iambic.core.parser import load_templates
Expand Down Expand Up @@ -597,6 +598,18 @@ def create_or_update_template(

try:
merged_template.write()

if ctx.command == Command.Import:
# https://github.com/noqdev/iambic/issues/600
# we want to assert against bad exclude_account statement
if isinstance(new_template, AccessModelMixin) and isinstance(
existing_template, AccessModelMixin
):
existing_access_model: AccessModelMixin = existing_template
new_access_model: AccessModelMixin = merged_template
if len(existing_access_model.excluded_children) == 0:
assert len(new_access_model.excluded_children) == 0

return merged_template
except Exception as err:
log.exception(
Expand All @@ -608,6 +621,14 @@ def create_or_update_template(
else:
try:
new_template.write()

if ctx.command == Command.Import:
# https://github.com/noqdev/iambic/issues/600
# we want to assert against bad exclude_account statement
if isinstance(new_template, AccessModelMixin):
access_model: AccessModelMixin = new_template
assert len(access_model.excluded_children) == 0

return new_template
except Exception as err:
log.exception(
Expand Down

0 comments on commit b94169f

Please sign in to comment.