Skip to content

Commit

Permalink
Merge pull request #251 from noqdev/task/en-1888-summary-before-apply…
Browse files Browse the repository at this point in the history
…-improve-proposed-changes

Task/en 1888 summary before apply improve proposed changes
  • Loading branch information
mdaue2 authored Mar 29, 2023
2 parents eb4170b + de2110c commit 115bb67
Show file tree
Hide file tree
Showing 47 changed files with 1,601 additions and 963 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ dmypy.json
.pyre/

# iambic
proposed_changes.txt
proposed_changes.json
proposed_changes.yaml
.DS_Store
Expand Down
44 changes: 44 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,50 @@
"console": "integratedTerminal",
"justMyCode": false
},
{
"name": "Iambic: Functional Tests",
"type": "python",
"request": "launch",
"module": "pytest",
"console": "integratedTerminal",
"args": [
"--disable-warnings",
"--cov=iambic",
"--cov-report=term-missing",
"--cov-report=html",
"--cov-report=xml",
"--cov-branch",
"--cov-fail-under=100",
"--junitxml=functional_tests/results.xml",
"--color=yes",
"--verbose",
"${workspaceFolder}/functional_tests",
],
"envFile": "${workspaceFolder}/.env",
"justMyCode": false
},
{
"name": "Iambic: Specific Functional Test",
"type": "python",
"request": "launch",
"module": "pytest",
"console": "integratedTerminal",
"envFile": "${workspaceFolder}/.env",
"args": [
"--disable-warnings",
"--cov=iambic",
"--cov-report=term-missing",
"--cov-report=html",
"--cov-report=xml",
"--cov-branch",
"--cov-fail-under=100",
"--junitxml=functional_tests/results.xml",
"--color=yes",
"--verbose",
"${workspaceFolder}/functional_tests/test_google_workspace.py::test_google",
],
"justMyCode": false
},
{
"name": "Iambic: Plan",
"type": "python",
Expand Down
9 changes: 3 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"python.testing.pytestArgs": [
".",
"-s"
],
"python.testing.pytestArgs": [],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.formatting.provider": "black",
Expand All @@ -11,12 +8,12 @@
"-s",
"./iambic",
"-p",
"*_test.py"
"*_test.py",
],
"coverage-gutters.coverageFileNames": [
"cov_unit_tests.xml"
],
"coverage-gutters.coverageBaseDir": ".",
"coverage-gutters.showGutterCoverage": false,
"coverage-gutters.showLineCoverage": true
"coverage-gutters.showLineCoverage": true,
}
10 changes: 7 additions & 3 deletions functional_tests/aws/group/test_create_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from functional_tests.aws.group.utils import generate_group_template_from_base
from functional_tests.aws.user.utils import get_modifiable_user
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.utils import get_group_across_accounts
from iambic.plugins.v0_1_0.aws.iam.user.utils import get_user_groups
from iambic.plugins.v0_1_0.aws.utils import boto_crud_call
Expand All @@ -30,9 +31,10 @@ async def test_create_group_all_accounts(self):
self.template.included_accounts = ["*"]
self.template.excluded_accounts = []

await self.template.apply(
changes = await self.template.apply(
IAMBIC_TEST_DETAILS.config.aws,
)
screen_render_resource_changes([changes])

account_group_mapping = await get_group_across_accounts(
IAMBIC_TEST_DETAILS.config.aws.accounts, self.group_name, False
Expand All @@ -53,9 +55,10 @@ async def test_create_group_on_single_account(self):
self.template.included_accounts = [included_account]
self.template.excluded_accounts = []

await self.template.apply(
changes = await self.template.apply(
IAMBIC_TEST_DETAILS.config.aws,
)
screen_render_resource_changes([changes])

account_group_mapping = await get_group_across_accounts(
IAMBIC_TEST_DETAILS.config.aws.accounts, self.group_name, False
Expand All @@ -81,9 +84,10 @@ async def test_create_group_and_attach_to_user(self):

self.template.included_accounts = [included_account]
self.template.excluded_accounts = []
await self.template.apply(
changes = await self.template.apply(
IAMBIC_TEST_DETAILS.config.aws,
)
screen_render_resource_changes([changes])

user = await get_modifiable_user(iam_client)
user_name = user["UserName"]
Expand Down
10 changes: 8 additions & 2 deletions functional_tests/aws/group/test_update_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

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.utils import get_group_across_accounts
from iambic.plugins.v0_1_0.aws.iam.policy.models import ManagedPolicyRef, PolicyDocument

Expand Down Expand Up @@ -55,7 +56,8 @@ async def test_update_managed_policies(self):
self.template.properties.managed_policies = [
ManagedPolicyRef(policy_arn=policy_arn)
]
await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
changes = await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
screen_render_resource_changes([changes])

account_group_mapping = await get_group_across_accounts(
IAMBIC_TEST_DETAILS.config.aws.accounts,
Expand All @@ -71,7 +73,8 @@ async def test_update_managed_policies(self):
)

self.template.properties.managed_policies = []
await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
changes = await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
screen_render_resource_changes([changes])

account_group_mapping = await get_group_across_accounts(
IAMBIC_TEST_DETAILS.config.aws.accounts,
Expand Down Expand Up @@ -129,6 +132,7 @@ async def test_create_update_group_all_accounts(self):
)
)
r = await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
screen_render_resource_changes(([r]))
self.assertEqual(len(r.proposed_changes), 2)

# Set expiration
Expand All @@ -138,6 +142,7 @@ async def test_create_update_group_all_accounts(self):
"yesterday", settings={"TIMEZONE": "UTC", "RETURN_AS_TIMEZONE_AWARE": True}
)
r = await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
screen_render_resource_changes(([r]))
self.assertEqual(len(r.proposed_changes), 1)


Expand Down Expand Up @@ -199,4 +204,5 @@ async def test_bad_input(self):
)
)
r = await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
screen_render_resource_changes(([r]))
self.assertEqual(len(r.exceptions_seen), 2)
10 changes: 7 additions & 3 deletions functional_tests/aws/managed_policy/test_create_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from functional_tests.aws.role.utils import get_modifiable_role
from functional_tests.conftest import IAMBIC_TEST_DETAILS
from iambic.core.utils import aio_wrapper
from iambic.output.text import screen_render_resource_changes
from iambic.plugins.v0_1_0.aws.iam.policy.utils import (
get_managed_policy_across_accounts,
get_managed_policy_attachments,
Expand All @@ -33,7 +34,8 @@ async def test_create_managed_policy_all_accounts(self):
self.template.included_accounts = ["*"]
self.template.excluded_accounts = []

await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
changes = await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
screen_render_resource_changes([changes])

account_mp_mapping = await get_managed_policy_across_accounts(
IAMBIC_TEST_DETAILS.config.aws.accounts, self.path, self.policy_name
Expand All @@ -54,7 +56,8 @@ async def test_create_managed_policy_on_single_account(self):
self.template.included_accounts = [included_account]
self.template.excluded_accounts = []

await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
changes = await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
screen_render_resource_changes([changes])

account_mp_mapping = await get_managed_policy_across_accounts(
IAMBIC_TEST_DETAILS.config.aws.accounts, self.path, self.policy_name
Expand All @@ -80,7 +83,8 @@ async def test_create_managed_policy_and_attach_to_role(self):

self.template.included_accounts = [included_account]
self.template.excluded_accounts = []
await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
changes = await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
screen_render_resource_changes([changes])

role = await get_modifiable_role(iam_client)
role_name = role["RoleName"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
managed_policy_full_import,
)
from functional_tests.conftest import IAMBIC_TEST_DETAILS
from iambic.output.text import screen_render_resource_changes
from iambic.plugins.v0_1_0.aws.event_bridge.models import ManagedPolicyMessageDetails
from iambic.plugins.v0_1_0.aws.iam.policy.models import AwsIamManagedPolicyTemplate

Expand Down Expand Up @@ -38,7 +39,8 @@ async def test_update_managed_policy_attribute(self):
self.template.write()

self.template.properties.description = updated_description
await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
changes = await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
screen_render_resource_changes([changes])

file_sys_template = AwsIamManagedPolicyTemplate.load(self.template.file_path)
self.assertEqual(file_sys_template.properties.description, initial_description)
Expand Down Expand Up @@ -96,7 +98,8 @@ async def test_delete_managed_policy_from_one_account(self):
self.assertNotIn(deleted_account, file_sys_template.excluded_accounts)

# Create the policy on all accounts except 1
await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
changes = await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
screen_render_resource_changes([changes])

# Refresh the template
await managed_policy_full_import(
Expand Down
2 changes: 2 additions & 0 deletions functional_tests/aws/managed_policy/test_update_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
)
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 Expand Up @@ -40,6 +41,7 @@ async def test_update_tag_with_bad_input(self):
template_change_details = await self.template.apply(
IAMBIC_TEST_DETAILS.config.aws,
)
screen_render_resource_changes([template_change_details])

self.assertGreater(
len(template_change_details.exceptions_seen),
Expand Down
7 changes: 5 additions & 2 deletions functional_tests/aws/permission_set/test_create_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
generate_permission_set_template_from_base,
)
from functional_tests.conftest import IAMBIC_TEST_DETAILS
from iambic.output.text import screen_render_resource_changes


class CreatePermissionSetTestCase(IsolatedAsyncioTestCase):
Expand All @@ -23,7 +24,8 @@ async def asyncTearDown(self):
await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)

async def test_create_permission_set(self):
await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
changes = await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
screen_render_resource_changes([changes])
await IAMBIC_TEST_DETAILS.identity_center_account.set_identity_center_details()

self.assertIn(
Expand All @@ -35,7 +37,8 @@ async def test_create_permission_set_with_account_assignment(self):
self.template = attach_access_rule(
self.template, IAMBIC_TEST_DETAILS.identity_center_account
)
await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
changes = await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
screen_render_resource_changes([changes])
await IAMBIC_TEST_DETAILS.identity_center_account.set_identity_center_details()

self.assertIn(
Expand Down
8 changes: 6 additions & 2 deletions functional_tests/aws/permission_set/test_update_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
)
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.identity_center.permission_set.models import (
PermissionSetAccess,
)
Expand Down Expand Up @@ -52,7 +53,8 @@ def tearDownClass(cls):

async def test_update_description(self):
self.template.properties.description = "Updated description"
await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
changes = await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
screen_render_resource_changes([changes])
await IAMBIC_TEST_DETAILS.identity_center_account.set_identity_center_details(
batch_size=5
)
Expand Down Expand Up @@ -98,7 +100,8 @@ async def test_account_assignment(self):

# test un-assignment
self.template.access_rules = []
await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
changes = await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
screen_render_resource_changes([changes])
cloud_access_rules = await get_permission_set_users_and_groups_as_access_rules(
identity_center_client,
IAMBIC_TEST_DETAILS.identity_center_account.identity_center_details.instance_arn,
Expand All @@ -114,6 +117,7 @@ async def test_update_invalid_description(self):
template_change_details = await self.template.apply(
IAMBIC_TEST_DETAILS.config.aws
)
screen_render_resource_changes([template_change_details])
self.assertEqual(
len(template_change_details.exceptions_seen),
1,
Expand Down
7 changes: 5 additions & 2 deletions functional_tests/aws/role/test_create_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from functional_tests.aws.role.utils import generate_role_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.role.utils import get_role_across_accounts


Expand All @@ -25,7 +26,8 @@ async def test_create_role_all_accounts(self):
self.template.included_accounts = ["*"]
self.template.excluded_accounts = []

await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
changes = await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
screen_render_resource_changes([changes])

account_role_mapping = await get_role_across_accounts(
IAMBIC_TEST_DETAILS.config.aws.accounts, self.role_name, False
Expand All @@ -46,7 +48,8 @@ async def test_create_role_on_single_account(self):
self.template.included_accounts = [included_account]
self.template.excluded_accounts = []

await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
changes = await self.template.apply(IAMBIC_TEST_DETAILS.config.aws)
screen_render_resource_changes([changes])

account_role_mapping = await get_role_across_accounts(
IAMBIC_TEST_DETAILS.config.aws.accounts, self.role_name, False
Expand Down
Loading

0 comments on commit 115bb67

Please sign in to comment.