Skip to content

Commit

Permalink
Merge pull request #410 from noqdev/bug/en-2119-fix-merge-model-int-h…
Browse files Browse the repository at this point in the history
…andling

Fix merge model int handling
  • Loading branch information
Will-NOQ committed May 15, 2023
2 parents 3172c5a + 7ca47ca commit f711e1f
Show file tree
Hide file tree
Showing 38 changed files with 671 additions and 511 deletions.
13 changes: 10 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
Expand All @@ -24,9 +25,15 @@ A clear and concise description of what you expected to happen.
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.

**Community Engagement**
Your vote counts! Please support this bug report by adding a 👍 reaction to the original issue, which will aid the community and maintainers in addressing this problem.

Please refrain from adding "+1" or "me too" comments, as these create unnecessary noise for issue followers and do not help in prioritizing the issue. If you wish to contribute to solving this issue or have submitted a pull request, please leave a comment.
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ A clear and concise description of any alternative solutions or features you've

**Additional context**
Add any other context or screenshots about the feature request here.

**Community Engagement**
Help us prioritize this request and express your support by adding a 👍 reaction to the original issue. This will assist both the community and the maintainers in addressing this request.

Please avoid leaving "+1" or "me too" comments as they create extra noise for issue followers and do not assist in prioritizing the request. If you are considering working on this issue or have already submitted a pull request, kindly leave a comment.
2 changes: 1 addition & 1 deletion .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
id: run-test
run: |
python3 -m venv env
. env/bin/activate && pip install poetry setuptools pip --upgrade && poetry install && make test
. env/bin/activate && pip install poetry setuptools pip --upgrade && poetry install && pre-commit run -a && make test
- name: Upload coverage reports to Codecov
if: ${{ github.repository == 'noqdev/iambic' }}
uses: codecov/codecov-action@v3
Expand Down
2 changes: 0 additions & 2 deletions .isort.cfg

This file was deleted.

15 changes: 6 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@ default_language_version:
python: python3.10
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0 # Use the ref you want to point at
rev: v4.1.0
hooks:
- id: trailing-whitespace
- id: check-ast
- id: check-case-conflict
- id: debug-statements
- id: check-yaml
args: [--allow-multiple-documents, --unsafe]
- repo: https://github.com/timothycrosley/isort
rev: "5.12.0"
hooks:
- id: isort
pass_filenames: true
- repo: local
hooks:
- id: isort
name: isort
stages: [commit]
language: system
entry: poetry run isort
types: [python]
args: ["--profile", "black", "-p", "iambic"]

- id: black
name: black
stages: [commit]
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@

# Change Log

## 0.7.6 (May 15th, 2023)

BUG FIXES:

* Handling merge models when the new value is an int
* Flatten multiline comment when they are not attached to a YAML dict key

ENHANCEMENTS:
* Added an `iambic convert` command to convert an AWS policy to the IAMbic formatted yaml

THANKS:

* `Shreyas D` for reporting the merge model issue
* `Phil H, Michael W` for suggesting the `iambic convert` command

## 0.7.3 (May 10th, 2023)

BUG FIXES:
Expand Down
2 changes: 1 addition & 1 deletion functional_tests/aws/group/test_update_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from unittest import IsolatedAsyncioTestCase

import dateparser

from functional_tests.aws.group.utils import generate_group_template_from_base
from functional_tests.conftest import IAMBIC_TEST_DETAILS

from iambic.output.text import screen_render_resource_changes
from iambic.plugins.v0_1_0.aws.iam.group.models import AwsIamGroupTemplate
from iambic.plugins.v0_1_0.aws.iam.group.utils import get_group_across_accounts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
generate_managed_policy_template_from_base,
)
from functional_tests.conftest import IAMBIC_TEST_DETAILS

from iambic.core import noq_json as json
from iambic.output.text import screen_render_resource_changes
from iambic.plugins.v0_1_0.aws.models import Tag
Expand Down
1 change: 0 additions & 1 deletion functional_tests/aws/managed_policy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import uuid

from functional_tests.conftest import IAMBIC_TEST_DETAILS

from iambic.core.iambic_enum import Command
from iambic.core.logger import log
from iambic.core.models import ExecutionMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
generate_permission_set_template_from_base,
)
from functional_tests.conftest import IAMBIC_TEST_DETAILS

from iambic.output.text import screen_render_resource_changes


Expand Down
1 change: 0 additions & 1 deletion functional_tests/aws/role/test_template_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
role_full_import,
)
from functional_tests.conftest import IAMBIC_TEST_DETAILS

from iambic.plugins.v0_1_0.aws.event_bridge.models import RoleMessageDetails
from iambic.plugins.v0_1_0.aws.iam.role.models import AwsIamRoleTemplate

Expand Down
1 change: 0 additions & 1 deletion functional_tests/aws/user/test_create_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from functional_tests.aws.user.utils import generate_user_template_from_base
from functional_tests.conftest import IAMBIC_TEST_DETAILS

from iambic.plugins.v0_1_0.aws.iam.user.utils import get_user_across_accounts


Expand Down
1 change: 0 additions & 1 deletion functional_tests/azure_ad/base_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from unittest import IsolatedAsyncioTestCase

from functional_tests.conftest import IAMBIC_TEST_DETAILS

from iambic.plugins.v0_1_0.azure_ad.group.models import GroupTemplateProperties
from iambic.plugins.v0_1_0.azure_ad.group.utils import list_groups
from iambic.plugins.v0_1_0.azure_ad.user.models import UserTemplateProperties
Expand Down
1 change: 0 additions & 1 deletion functional_tests/azure_ad/group/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import uuid

from functional_tests.conftest import IAMBIC_TEST_DETAILS

from iambic.core.iambic_enum import Command
from iambic.core.models import ExecutionMessage
from iambic.plugins.v0_1_0.azure_ad.group.models import (
Expand Down
1 change: 0 additions & 1 deletion functional_tests/azure_ad/user/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import random

from functional_tests.conftest import IAMBIC_TEST_DETAILS

from iambic.plugins.v0_1_0.azure_ad.user.models import AzureActiveDirectoryUserTemplate


Expand Down
1 change: 0 additions & 1 deletion functional_tests/okta/group/test_okta_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os

from functional_tests.conftest import IAMBIC_TEST_DETAILS

from iambic.core.iambic_enum import IambicManaged
from iambic.core.parser import load_templates
from iambic.main import run_apply
Expand Down
1 change: 0 additions & 1 deletion functional_tests/test_config_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from unittest import IsolatedAsyncioTestCase

from functional_tests.conftest import IAMBIC_TEST_DETAILS

from iambic.config.dynamic_config import load_config
from iambic.core.iambic_enum import Command
from iambic.core.models import ExecutionMessage
Expand Down
2 changes: 2 additions & 0 deletions functional_tests/test_wizard.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
import random
import tempfile
Expand Down
56 changes: 48 additions & 8 deletions iambic/core/template_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from iambic.core.models import AccessModelMixin, BaseModel, BaseTemplate, ProviderChild
from iambic.core.parser import load_templates
from iambic.core.utils import (
IAMBIC_ERR_MSG,
evaluate_on_provider,
gather_templates,
get_provider_value,
Expand Down Expand Up @@ -898,7 +899,7 @@ def merge_model_list(
return merged_list


def merge_model(
def merge_model( # noqa: C901
new_model: BaseModel,
existing_model: BaseModel,
all_provider_children: list[ProviderChild],
Expand Down Expand Up @@ -990,16 +991,55 @@ def merge_model(
elif not isinstance(new_value, list):
new_value = [new_value]

new_value = merge_access_model_list(
new_value, existing_value, all_provider_children
)
if all(isinstance(x, AccessModelMixin) for x in new_value):
try:
new_value = merge_access_model_list(
new_value, existing_value, all_provider_children
)
except Exception as err:
log.exception(
f"Failed to merge template attribute. {IAMBIC_ERR_MSG}",
key=key,
new_value=[
{"value": str(val), "type": type(val)}
for val in new_value
],
existing_value=[
{"value": str(val), "type": type(val)}
for val in existing_value
],
err=repr(err),
)
raise

setattr(
merged_model, key, new_value if value_as_list else new_value[0]
)
elif isinstance(inner_element, BaseModel):
new_value = merge_model_list(
new_value, existing_value, all_provider_children
)
if not isinstance(new_value, list):
new_value = [new_value]

if all(isinstance(x, BaseModel) for x in new_value):
try:
new_value = merge_model_list(
new_value, existing_value, all_provider_children
)
except Exception as err:
log.exception(
f"Failed to merge template attribute. {IAMBIC_ERR_MSG}",
key=key,
new_value=[
{"value": str(val), "type": type(val)}
for val in new_value
],
existing_value=[
{"value": str(val), "type": type(val)}
for val in existing_value
],
err=repr(err),
)
raise

setattr(
merged_model, key, new_value if value_as_list else new_value[0]
)
Expand Down Expand Up @@ -1030,7 +1070,7 @@ def merge_model(
setattr(merged_model, key, new_value)
else:
raise TypeError(
f"Type of {type(new_value)} is not supported. Please file a github issue"
f"Type of {type(new_value)} is not supported. {IAMBIC_ERR_MSG}"
)
elif key not in iambic_fields:
setattr(merged_model, key, new_value)
Expand Down
5 changes: 5 additions & 0 deletions iambic/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@

NOQ_TEMPLATE_REGEX = r".*template_type:\n?.*NOQ::"
RATE_LIMIT_STORAGE: dict[str, int] = {}
IAMBIC_ERR_MSG = (
"Please file a github issue or message us on the slack community channel. "
"Include as much of the traceback and this error message as possible. "
"Be sure to redact any sensitive information."
)

__WRITABLE_DIRECTORY__ = pathlib.Path.home()

Expand Down
7 changes: 6 additions & 1 deletion iambic/plugins/v0_1_0/aws/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ readme = "README.md"
exclude = ["build_util/*"]

[tool.isort]
known_first_party = ["iambic"]
src_paths = ["iambic","test","functional_tests","build_utils"]
known_third_party = ["_pytest", "okta", "github", "pydantic", "rich"]
profile = "black"
add_imports = "from __future__ import annotations"
add_imports = ["from __future__ import annotations"]
skip_gitignore = true
line_length = 88

[tool.poetry.dependencies]
python = "^3.10"
Expand Down
2 changes: 2 additions & 0 deletions iambic/plugins/v0_1_0/aws/template_generation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Union

from iambic.core.template_generation import (
Expand Down
7 changes: 6 additions & 1 deletion iambic/plugins/v0_1_0/google_workspace/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ readme = "README.md"
exclude = ["build_util/*"]

[tool.isort]
known_first_party = ["iambic"]
src_paths = ["iambic","test","functional_tests","build_utils"]
known_third_party = ["_pytest", "okta", "github", "pydantic", "rich"]
profile = "black"
add_imports = "from __future__ import annotations"
add_imports = ["from __future__ import annotations"]
skip_gitignore = true
line_length = 88

[tool.poetry.dependencies]
python = "^3.10"
Expand Down
7 changes: 6 additions & 1 deletion iambic/plugins/v0_1_0/okta/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ readme = "README.md"
exclude = ["build_util/*"]

[tool.isort]
known_first_party = ["iambic"]
src_paths = ["iambic","test","functional_tests","build_utils"]
known_third_party = ["_pytest", "okta", "github", "pydantic", "rich"]
profile = "black"
add_imports = "from __future__ import annotations"
add_imports = ["from __future__ import annotations"]
skip_gitignore = true
line_length = 88

[tool.poetry.dependencies]
python = "^3.10"
Expand Down
2 changes: 2 additions & 0 deletions iambic/vendor/lambda_multiprocessing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from iambic.vendor.lambda_multiprocessing.main import AsyncResult, Pool, TimeoutError

__all__ = ["Pool", "TimeoutError", "AsyncResult"]
Loading

0 comments on commit f711e1f

Please sign in to comment.