Skip to content

Commit

Permalink
Merge pull request #773 from guardian/aa-rm-circular-deps
Browse files Browse the repository at this point in the history
fix: Remove circular dependencies
  • Loading branch information
akash1810 authored Sep 8, 2021
2 parents 9306380 + 3c1194e commit 1f1735d
Show file tree
Hide file tree
Showing 21 changed files with 79 additions and 60 deletions.
40 changes: 29 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"cli:dev": "ts-node src/bin/index.ts"
},
"devDependencies": {
"@guardian/eslint-config-typescript": "^0.6.1",
"@guardian/eslint-config-typescript": "0.7.0",
"@types/aws-lambda": "^8.10.83",
"@types/git-url-parse": "^9.0.1",
"@types/jest": "^27.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/constructs/core/migrating.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SynthUtils } from "@aws-cdk/assert";
import { Bucket } from "@aws-cdk/aws-s3";
import type { BucketProps } from "@aws-cdk/aws-s3";
import { Annotations } from "@aws-cdk/core";
import type { GuStatefulConstruct } from "../../utils/mixin";
import type { GuStatefulConstruct } from "../../types/migrating";
import { simpleGuStackForTesting } from "../../utils/test";
import type { SynthedStack } from "../../utils/test";
import { GuMigratingResource } from "./migrating";
Expand Down
20 changes: 2 additions & 18 deletions src/constructs/core/migrating.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
import { Annotations } from "@aws-cdk/core";
import type { CfnElement, IConstruct } from "@aws-cdk/core";
import { isGuStatefulConstruct } from "../../utils/mixin";

export interface GuMigratingStack {
/**
* A flag to symbolise if a stack is being migrated from a previous format (eg YAML) into guardian/cdk.
* A value of `true` means resources in the stack can have custom logicalIds set using the property `existingLogicalId` (where available).
* A value of `false` or `undefined` means the stack is brand new. Any resource that gets created will have an auto-generated logicalId.
* Ideally, for use only by [[ `GuStack` ]].
* @see GuMigratingResource
* @see GuStack
*/
migratedFromCloudFormation: boolean;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types -- user defined type guard
export function isGuMigratingStack(construct: any): construct is GuMigratingStack {
return "migratedFromCloudFormation" in construct;
}
import type { GuMigratingStack } from "../../types/migrating";
import { isGuStatefulConstruct } from "../../types/migrating";

export interface GuMigratingResource {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/constructs/core/parameters/anghammarad.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SSM_PARAMETER_PATHS } from "../../../constants/ssm-parameter-paths";
import { isSingletonPresentInStack } from "../../../utils/test";
import { isSingletonPresentInStack } from "../../../utils/singleton";
import type { GuStack } from "../stack";
import { GuStringParameter } from "./base";

Expand Down
2 changes: 1 addition & 1 deletion src/constructs/core/parameters/identity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Stage, Stages } from "../../../constants";
import { isSingletonPresentInStack } from "../../../utils/test";
import { isSingletonPresentInStack } from "../../../utils/singleton";
import type { GuStack } from "../stack";
import { GuStringParameter } from "./base";

Expand Down
2 changes: 1 addition & 1 deletion src/constructs/core/parameters/log-shipping.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SSM_PARAMETER_PATHS } from "../../../constants/ssm-parameter-paths";
import { isSingletonPresentInStack } from "../../../utils/test";
import { isSingletonPresentInStack } from "../../../utils/singleton";
import type { GuStack } from "../stack";
import { GuStringParameter } from "./base";

Expand Down
2 changes: 1 addition & 1 deletion src/constructs/core/parameters/s3.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SSM_PARAMETER_PATHS } from "../../../constants/ssm-parameter-paths";
import { isSingletonPresentInStack } from "../../../utils/test";
import { isSingletonPresentInStack } from "../../../utils/singleton";
import type { GuStack } from "../stack";
import { GuStringParameter } from "./base";

Expand Down
2 changes: 1 addition & 1 deletion src/constructs/core/parameters/vpc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SSM_PARAMETER_PATHS } from "../../../constants/ssm-parameter-paths";
import { isSingletonPresentInStack } from "../../../utils/test";
import { isSingletonPresentInStack } from "../../../utils/singleton";
import type { GuStack } from "../stack";
import { GuParameter } from "./base";
import type { GuNoTypeParameterProps } from "./base";
Expand Down
2 changes: 1 addition & 1 deletion src/constructs/core/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { Stage } from "../../constants";
import { ContextKeys } from "../../constants/context-keys";
import { TagKeys } from "../../constants/tag-keys";
import { TrackingTag } from "../../constants/tracking-tag";
import type { GuMigratingStack } from "../../types/migrating";
import { Logger } from "../../utils/logger";
import type { StackStageIdentity } from "./identity";
import { GuStageMapping } from "./mappings";
import type { GuStageDependentValue } from "./mappings";
import type { GuMigratingStack } from "./migrating";
import { GuStageParameter } from "./parameters";
import type { GuParameter } from "./parameters";

Expand Down
2 changes: 1 addition & 1 deletion src/constructs/ec2/security-groups/wazuh.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Peer } from "@aws-cdk/aws-ec2";
import type { IVpc } from "@aws-cdk/aws-ec2";
import { isSingletonPresentInStack } from "../../../utils/test";
import { isSingletonPresentInStack } from "../../../utils/singleton";
import type { GuStack } from "../../core";
import { GuMigratingResource } from "../../core/migrating";
import { GuBaseSecurityGroup } from "./base";
Expand Down
2 changes: 1 addition & 1 deletion src/constructs/iam/policies/anghammarad.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isSingletonPresentInStack } from "../../../utils/test";
import { isSingletonPresentInStack } from "../../../utils/singleton";
import type { GuStack } from "../../core";
import { GuAnghammaradTopicParameter } from "../../core";
import { GuAllowPolicy } from "./base-policy";
Expand Down
2 changes: 1 addition & 1 deletion src/constructs/iam/policies/describe-ec2.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Effect, PolicyStatement } from "@aws-cdk/aws-iam";
import { isSingletonPresentInStack } from "../../../utils/test";
import { isSingletonPresentInStack } from "../../../utils/singleton";
import type { GuStack } from "../../core";
import { GuPolicy } from "./base-policy";

Expand Down
2 changes: 1 addition & 1 deletion src/constructs/iam/policies/log-shipping.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isSingletonPresentInStack } from "../../../utils/test";
import { isSingletonPresentInStack } from "../../../utils/singleton";
import type { GuStack } from "../../core";
import { GuLoggingStreamNameParameter } from "../../core/parameters/log-shipping";
import { GuAllowPolicy } from "./base-policy";
Expand Down
2 changes: 1 addition & 1 deletion src/constructs/iam/policies/ssm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isSingletonPresentInStack } from "../../../utils/test";
import { isSingletonPresentInStack } from "../../../utils/singleton";
import type { GuStack } from "../../core";
import { GuAllowPolicy } from "./base-policy";

Expand Down
29 changes: 29 additions & 0 deletions src/types/migrating.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export interface GuMigratingStack {
/**
* A flag to symbolise if a stack is being migrated from a previous format (eg YAML) into guardian/cdk.
* A value of `true` means resources in the stack can have custom logicalIds set using the property `existingLogicalId` (where available).
* A value of `false` or `undefined` means the stack is brand new. Any resource that gets created will have an auto-generated logicalId.
* Ideally, for use only by [[ `GuStack` ]].
* @see GuMigratingResource
* @see GuStack
*/
migratedFromCloudFormation: boolean;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types -- user defined type guard
export function isGuMigratingStack(construct: any): construct is GuMigratingStack {
return "migratedFromCloudFormation" in construct;
}

export interface GuStatefulConstruct {
/**
* A flag to signal to `GuMigratingResource` that a construct is stateful and care should be taken when migrating to GuCDK.
* If one accidentally replaces a stateful resource, downstream services such as DNS may be impacted.
*/
isStatefulConstruct: true;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types -- user defined type guard
export function isGuStatefulConstruct(construct: any): construct is GuStatefulConstruct {
return "isStatefulConstruct" in construct;
}
14 changes: 1 addition & 13 deletions src/utils/mixin/migratable-construct-stateful.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
import type { GuStatefulConstruct } from "../../types/migrating";
import { GuMigratableConstruct } from "./migratable-construct";
import type { AnyConstructor } from "./types";

export interface GuStatefulConstruct {
/**
* A flag to signal to `GuMigratingResource` that a construct is stateful and care should be taken when migrating to GuCDK.
* If one accidentally replaces a stateful resource, downstream services such as DNS may be impacted.
*/
isStatefulConstruct: true;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types -- user defined type guard
export function isGuStatefulConstruct(construct: any): construct is GuStatefulConstruct {
return "isStatefulConstruct" in construct;
}

/**
* A mixin to add the property `isStatefulConstruct` to a class and execute logic to conditionally override a construct's logicalId when synthesised.
*
Expand Down
5 changes: 3 additions & 2 deletions src/utils/mixin/migratable-construct.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Construct } from "@aws-cdk/core";
import { GuMigratingResource, isGuMigratingStack } from "../../constructs/core/migrating";
import type { GuMigratingStack } from "../../constructs/core/migrating";
import { GuMigratingResource } from "../../constructs/core/migrating";
import type { GuMigratingStack } from "../../types/migrating";
import { isGuMigratingStack } from "../../types/migrating";
import type { AnyConstructor } from "./types";

/**
Expand Down
2 changes: 1 addition & 1 deletion src/utils/test/singleton.ts → src/utils/singleton.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Stack } from "@aws-cdk/core/lib/stack";
import type { GuStack } from "../../constructs/core";
import type { GuStack } from "../constructs/core";

/**
* Check if an element exists in a [[`GuStack`]].
Expand Down
1 change: 0 additions & 1 deletion src/utils/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./simple-gu-stack";
export * from "./synthed-stack";
export * from "./attach-policy-to-test-role";
export * from "./singleton";
2 changes: 1 addition & 1 deletion tools/integration-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"generate": "cdk synth --path-metadata false --version-reporting false"
},
"devDependencies": {
"@guardian/eslint-config-typescript": "^0.6.0",
"@guardian/eslint-config-typescript": "0.7.0",
"@types/jest": "^27.0.1",
"@types/node": "16.7.10",
"aws-cdk": "1.120.0",
Expand Down

0 comments on commit 1f1735d

Please sign in to comment.