Skip to content

Commit

Permalink
Attaching and detaching role tags now 2 distinct operations. Fixes to…
Browse files Browse the repository at this point in the history
… role attribute value resolver on Role._apply_to_account.
  • Loading branch information
Will-NOQ committed Aug 1, 2023
1 parent f7b9096 commit c5cab58
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 6 additions & 6 deletions iambic/plugins/v0_1_0/aws/iam/role/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,17 @@ async def _apply_to_account( # noqa: C901
"MaxSessionDuration": "max_session_duration",
}
update_resource_log_params = {**log_params}
update_role_params = {}
update_role_keys = set()

Check warning on line 318 in iambic/plugins/v0_1_0/aws/iam/role/models.py

View check run for this annotation

Codecov / codecov/patch

iambic/plugins/v0_1_0/aws/iam/role/models.py#L318

Added line #L318 was not covered by tests
for k in supported_update_key_values.keys():
if account_role.get(k) is not None and account_role.get(
k
) != current_role.get(k):
update_resource_log_params[k] = dict(
old_value=current_role.get(k), new_value=account_role.get(k)
)
update_role_params[k] = current_role.get(k)
update_role_keys.add(k)

Check warning on line 326 in iambic/plugins/v0_1_0/aws/iam/role/models.py

View check run for this annotation

Codecov / codecov/patch

iambic/plugins/v0_1_0/aws/iam/role/models.py#L326

Added line #L326 was not covered by tests

if update_role_params:
if update_role_keys:

Check warning on line 328 in iambic/plugins/v0_1_0/aws/iam/role/models.py

View check run for this annotation

Codecov / codecov/patch

iambic/plugins/v0_1_0/aws/iam/role/models.py#L328

Added line #L328 was not covered by tests
log_str = "Out of date resource found."
if ctx.execute:
log.debug(
Expand All @@ -339,13 +339,13 @@ async def update_role():
await boto_crud_call(
client.update_role,
RoleName=role_name,
**update_role_params,
**{key: account_role[key] for key in update_role_keys},
)
except Exception as e:
exceptions.append(str(e))

proposed_role_changes = []
for key in update_role_params.keys():
for key in update_role_keys:

Check warning on line 348 in iambic/plugins/v0_1_0/aws/iam/role/models.py

View check run for this annotation

Codecov / codecov/patch

iambic/plugins/v0_1_0/aws/iam/role/models.py#L348

Added line #L348 was not covered by tests
proposed_role_changes.append(
ProposedChange(
attribute=key,
Expand All @@ -362,7 +362,7 @@ async def update_role():
tasks.append(update_role())
else:
log.debug(log_str, **update_resource_log_params)
for key in update_role_params.keys():
for key in update_role_keys:

Check warning on line 365 in iambic/plugins/v0_1_0/aws/iam/role/models.py

View check run for this annotation

Codecov / codecov/patch

iambic/plugins/v0_1_0/aws/iam/role/models.py#L365

Added line #L365 was not covered by tests
account_change_details.proposed_changes.append(
ProposedChange(
attribute=key,
Expand Down
8 changes: 8 additions & 0 deletions iambic/plugins/v0_1_0/aws/iam/role/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ async def untag_role():

log.debug(log_str, tags=tags_to_remove, **log_params)

if tasks:
results: list[list[ProposedChange]] = await asyncio.gather(
*tasks, return_exceptions=True
)
for r in results:
response.extend(r)

tasks = []
if tags_to_apply:
log_str = "New tags discovered in AWS."

Expand Down

0 comments on commit c5cab58

Please sign in to comment.