Skip to content

Commit

Permalink
Revert "fix(speed): I cannot figure exactly why, but the type guard f…
Browse files Browse the repository at this point in the history
…ile massively slowed down synth."

This reverts commit c6a1db1.
  • Loading branch information
mdial89f committed Aug 6, 2024
1 parent 23088b5 commit 51d9c3b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
16 changes: 7 additions & 9 deletions lib/local-aspects/iam-path/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IAspect } from "aws-cdk-lib";
import { IConstruct } from "constructs";
import * as iam from "aws-cdk-lib/aws-iam";
import { isCfnRole, isCfnUser, isCfnGroup } from "shared-utils";

export class IamPathAspect implements IAspect {
private readonly iamPath: string;
Expand All @@ -10,19 +11,16 @@ export class IamPathAspect implements IAspect {
}

public visit(node: IConstruct): void {
if (node instanceof iam.Role) {
const roleResource = node.node.defaultChild as iam.CfnRole;
roleResource.addPropertyOverride("Path", this.iamPath);
if (node instanceof iam.Role && isCfnRole(node.node.defaultChild)) {
node.node.defaultChild?.addPropertyOverride("Path", this.iamPath);
}

if (node instanceof iam.User) {
const userResource = node.node.defaultChild as iam.CfnUser;
userResource.addPropertyOverride("Path", this.iamPath);
if (node instanceof iam.User && isCfnUser(node.node.defaultChild)) {
node.node.defaultChild.addPropertyOverride("Path", this.iamPath);
}

if (node instanceof iam.Group) {
const groupResource = node.node.defaultChild as iam.CfnGroup;
groupResource.addPropertyOverride("Path", this.iamPath);
if (node instanceof iam.Group && isCfnGroup(node.node.defaultChild)) {
node.node.defaultChild.addPropertyOverride("Path", this.iamPath);
}
}
}
9 changes: 6 additions & 3 deletions lib/local-aspects/iam-permissions-boundary/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IAspect } from "aws-cdk-lib";
import { IConstruct } from "constructs";
import * as iam from "aws-cdk-lib/aws-iam";
import { isCfnRole } from "shared-utils";

export class IamPermissionsBoundaryAspect implements IAspect {
private readonly permissionsBoundaryArn: string;
Expand All @@ -10,9 +11,11 @@ export class IamPermissionsBoundaryAspect implements IAspect {
}

public visit(node: IConstruct): void {
if (node instanceof iam.Role) {
const roleResource = node.node.defaultChild as iam.CfnRole;
roleResource.addPropertyOverride("Path", this.permissionsBoundaryArn);
if (node instanceof iam.Role && isCfnRole(node.node.defaultChild)) {
node.node.defaultChild.addPropertyOverride(
"PermissionsBoundary",
this.permissionsBoundaryArn,
);
}
}
}
13 changes: 13 additions & 0 deletions lib/packages/shared-utils/cdk-type-guards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as iam from "aws-cdk-lib/aws-iam";

export function isCfnRole(child: any): child is iam.CfnRole {
return child instanceof iam.CfnRole;
}

export function isCfnUser(child: any): child is iam.CfnUser {
return child instanceof iam.CfnUser;
}

export function isCfnGroup(child: any): child is iam.CfnGroup {
return child instanceof iam.CfnGroup;
}
1 change: 1 addition & 0 deletions lib/packages/shared-utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./cdk-type-guards";
export * from "./feature-flags";
export * from "./package-actions/getAvailableActions";
export * from "./package-check";
Expand Down

0 comments on commit 51d9c3b

Please sign in to comment.