-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from alma-cdk/beta-add-warnings
chore: add warnings about use of to-be-deprecated feature flags
- Loading branch information
Showing
13 changed files
with
170 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./legacyTags"; | ||
export * from "./v0Tags"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useLegacyTags, LEGACY_TAGS_CONTEXT_KEY } from "./legacyTags"; | ||
import { TestableResource } from "../__test__/TestableResource"; | ||
|
||
describe("useLegacyTags", () => { | ||
test("context key is correct", () => { | ||
expect(LEGACY_TAGS_CONTEXT_KEY).toBe("@alma-cdk/project:legacyTags"); | ||
}); | ||
|
||
test("returns false if the context key is not set", () => { | ||
const scope = new TestableResource(); | ||
expect(useLegacyTags(scope)).toBe(false); | ||
}); | ||
|
||
test("returns true if the context key is set", () => { | ||
const scope = new TestableResource({ | ||
context: { | ||
"@alma-cdk/project:legacyTags": true, | ||
}, | ||
}); | ||
expect(useLegacyTags(scope)).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Construct } from "constructs"; | ||
|
||
export const LEGACY_TAGS_CONTEXT_KEY = "@alma-cdk/project:legacyTags"; | ||
|
||
/** | ||
* Enforces usage of https://github.com/almamedia/alma-cdk-jsii-tag-and-name | ||
* (for AWS CDK v1) compatible tagging behavior. | ||
* | ||
* @deprecated This behavior is not encouraged and will be removed in v2. Additionally according to GitHub search, this is not used anymore. | ||
*/ | ||
export function useLegacyTags(scope: Construct): boolean { | ||
return scope.node.tryGetContext(LEGACY_TAGS_CONTEXT_KEY) === true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useCompatibilityV0Tags, V0_TAGS_CONTEXT_KEY } from "./v0Tags"; | ||
import { TestableResource } from "../__test__/TestableResource"; | ||
|
||
describe("useCompatibilityV0Tags", () => { | ||
test("context key is correct", () => { | ||
expect(V0_TAGS_CONTEXT_KEY).toBe("@alma-cdk/project:compatibility:v0:tags"); | ||
}); | ||
|
||
test("returns false if the context key is not set", () => { | ||
const scope = new TestableResource(); | ||
expect(useCompatibilityV0Tags(scope)).toBe(false); | ||
}); | ||
|
||
test("returns true if the context key is set", () => { | ||
const scope = new TestableResource({ | ||
context: { | ||
"@alma-cdk/project:compatibility:v0:tags": true, | ||
}, | ||
}); | ||
expect(useCompatibilityV0Tags(scope)).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Construct } from "constructs"; | ||
|
||
export const V0_TAGS_CONTEXT_KEY = "@alma-cdk/project:compatibility:v0:tags"; | ||
|
||
/** | ||
* Compatibility flag for v0 tagging behavior. | ||
* Due to a bug in v0, the `Contact` and `Organization` tags were NOT applied as they should have. | ||
* This flag can be used to enforce behavior that matches v0 implementation: | ||
* I.e. `Contact` and `Organization` tags are NOT applied. | ||
* | ||
* @deprecated This behavior is not encouraged and will be removed in v2. | ||
*/ | ||
export function useCompatibilityV0Tags(scope: Construct): boolean { | ||
return scope.node.tryGetContext(V0_TAGS_CONTEXT_KEY) === true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { warnAboutDeprecatedTags } from "./deprecation-warnings"; | ||
import { expectErrorMetadata } from "../__test__/expectErrorMetadata"; | ||
import { TestableResource } from "../__test__/TestableResource"; | ||
|
||
describe("@alma-cdk/project:legacyTags", () => { | ||
test("feature flag present", () => { | ||
const testable = new TestableResource({ | ||
context: { | ||
"@alma-cdk/project:legacyTags": true, | ||
}, | ||
}); | ||
|
||
warnAboutDeprecatedTags(testable); | ||
|
||
expectErrorMetadata( | ||
testable, | ||
expect.stringContaining("@alma-cdk/project@v1:legacy-tags"), | ||
); | ||
}); | ||
|
||
test("feature flag missing", () => { | ||
const testable = new TestableResource(); | ||
|
||
warnAboutDeprecatedTags(testable); | ||
|
||
expectErrorMetadata(testable, undefined); | ||
}); | ||
}); | ||
|
||
describe("@alma-cdk/project:compatibility:v0:tags", () => { | ||
test("feature flag present", () => { | ||
const testable = new TestableResource({ | ||
context: { | ||
"@alma-cdk/project:compatibility:v0:tags": true, | ||
}, | ||
}); | ||
|
||
warnAboutDeprecatedTags(testable); | ||
|
||
expectErrorMetadata( | ||
testable, | ||
expect.stringContaining("@alma-cdk/project@v1:compatibility-v0-tags"), | ||
); | ||
}); | ||
|
||
test("feature flag missing", () => { | ||
const testable = new TestableResource(); | ||
|
||
warnAboutDeprecatedTags(testable); | ||
|
||
expectErrorMetadata(testable, undefined); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Annotations } from "aws-cdk-lib"; | ||
import { Construct } from "constructs"; | ||
import { | ||
useLegacyTags, | ||
useCompatibilityV0Tags, | ||
LEGACY_TAGS_CONTEXT_KEY, | ||
V0_TAGS_CONTEXT_KEY, | ||
} from "../feature-flags"; | ||
|
||
export function warnAboutDeprecatedTags(scope: Construct) { | ||
if (useLegacyTags(scope)) { | ||
Annotations.of(scope).addWarningV2( | ||
"@alma-cdk/project@v1:legacy-tags", | ||
`Using @almamedia-cdk/tag-and-name (for AWS CDK v1) construct's legacy tagging behavior via "${LEGACY_TAGS_CONTEXT_KEY}" context key. This is not encouraged and will be removed in v2.`, | ||
); | ||
} | ||
|
||
if (useCompatibilityV0Tags(scope)) { | ||
Annotations.of(scope).addWarningV2( | ||
"@alma-cdk/project@v1:compatibility-v0-tags", | ||
`Using @alma-cdk/project@v0 construct's tagging behavior via "${V0_TAGS_CONTEXT_KEY}" context key. You should migrate to using the default tagging behavior as this feature flag will be removed in v2.`, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters