-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add Tokenization.isResolvable for aspects
Add an example of a validating aspect, add `Tokenization.isResolvable()` to make it easier/possible to rule out `IResolvable`s from L1 properties. Included unit tests validates that the bug reported in #3026 is not systemic.
- Loading branch information
Showing
4 changed files
with
65 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// import { expect, haveResource, haveResourceLike, SynthUtils } from '@aws-cdk/assert'; | ||
import { SynthUtils } from '@aws-cdk/assert'; | ||
import cdk = require('@aws-cdk/core'); | ||
import { Stack, Tokenization } from '@aws-cdk/core'; | ||
import { Test } from 'nodeunit'; | ||
import s3 = require('../lib'); | ||
|
||
export = { | ||
'bucket must have versioning: failure'(test: Test) { | ||
// GIVEN | ||
const stack = new Stack(); | ||
new s3.Bucket(stack, 'MyBucket'); | ||
|
||
// WHEN | ||
stack.node.applyAspect(new BucketVersioningChecker()); | ||
|
||
// THEN | ||
const assembly = SynthUtils.synthesize(stack); | ||
const errorMessage = assembly.messages.find(m => m.entry.data === 'Bucket versioning is not enabled'); | ||
test.ok(errorMessage, 'Error message not reported'); | ||
|
||
test.done(); | ||
}, | ||
|
||
'bucket must have versioning: success'(test: Test) { | ||
// GIVEN | ||
const stack = new Stack(); | ||
new s3.Bucket(stack, 'MyBucket', { | ||
versioned: true | ||
}); | ||
|
||
// WHEN | ||
stack.node.applyAspect(new BucketVersioningChecker()); | ||
|
||
// THEN | ||
const assembly = SynthUtils.synthesize(stack); | ||
test.deepEqual(assembly.messages, []); | ||
|
||
test.done(); | ||
}, | ||
}; | ||
|
||
class BucketVersioningChecker implements cdk.IAspect { | ||
public visit(node: cdk.IConstruct): void { | ||
if (node instanceof s3.CfnBucket) { | ||
if (!node.versioningConfiguration || | ||
(!Tokenization.isResolvable(node.versioningConfiguration) && node.versioningConfiguration.status !== 'Enabled')) { | ||
node.node.addError('Bucket versioning is not enabled'); | ||
} | ||
} | ||
} | ||
} |
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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.