-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(kms): cross-stack usage detection depends on NPM tree #15580
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,7 +201,7 @@ abstract class KeyBase extends Resource implements IKey { | |
*/ | ||
private granteeStackDependsOnKeyStack(grantee: iam.IGrantable): string | undefined { | ||
const grantPrincipal = grantee.grantPrincipal; | ||
if (!(grantPrincipal instanceof Construct)) { | ||
if (!isConstruct(grantPrincipal)) { | ||
return undefined; | ||
} | ||
// this logic should only apply to newly created | ||
|
@@ -229,7 +229,7 @@ abstract class KeyBase extends Resource implements IKey { | |
} | ||
|
||
private isGranteeFromAnotherRegion(grantee: iam.IGrantable): boolean { | ||
if (!(grantee instanceof Construct)) { | ||
if (!isConstruct(grantee)) { | ||
return false; | ||
} | ||
const bucketStack = Stack.of(this); | ||
|
@@ -238,7 +238,7 @@ abstract class KeyBase extends Resource implements IKey { | |
} | ||
|
||
private isGranteeFromAnotherAccount(grantee: iam.IGrantable): boolean { | ||
if (!(grantee instanceof Construct)) { | ||
if (!isConstruct(grantee)) { | ||
return false; | ||
} | ||
const bucketStack = Stack.of(this); | ||
|
@@ -675,3 +675,20 @@ export class Key extends KeyBase { | |
})); | ||
} | ||
} | ||
|
||
/** | ||
* Whether the given object is a Construct | ||
* | ||
* Normally we'd do `x instanceof Construct`, but that is not robust against | ||
* multiple copies of the `constructs` library on disk. This can happen | ||
* when upgrading and downgrading between v2 and v1, and in the use of CDK | ||
* Pipelines is going to an error that says "Can't use Pipeline/Pipeline/Role in | ||
* a cross-environment fahsion", which is very confusing. | ||
*/ | ||
function isConstruct(x: any): x is Construct { | ||
const sym = Symbol.for('constructs.Construct.node'); | ||
return (typeof x === 'object' && x && | ||
(x instanceof Construct // happy fast case | ||
|| !!(x as Construct).node // constructs v10 | ||
|| !!(x as any)[sym])); // constructs v3 | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is how production software looks like! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we move this to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For sure. Don't forget to add it to both versions :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fashion