-
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
fix(iam): support NotActions/NotResources (#964) #3677
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 |
---|---|---|
|
@@ -14,16 +14,20 @@ export class PolicyStatement { | |
public effect: Effect; | ||
|
||
private action = new Array<any>(); | ||
private notaction = new Array<any>(); | ||
private principal: { [key: string]: any[] } = {}; | ||
private resource = new Array<any>(); | ||
private notresource = new Array<any>(); | ||
private condition: { [key: string]: any } = { }; | ||
|
||
constructor(props: PolicyStatementProps = {}) { | ||
this.effect = props.effect || Effect.ALLOW; | ||
|
||
this.addActions(...props.actions || []); | ||
this.addNotActions(...props.notactions || []); | ||
this.addPrincipals(...props.principals || []); | ||
this.addResources(...props.resources || []); | ||
this.addNotResources(...props.notresources || []); | ||
if (props.conditions !== undefined) { | ||
this.addConditions(props.conditions); | ||
} | ||
|
@@ -37,6 +41,10 @@ export class PolicyStatement { | |
this.action.push(...actions); | ||
} | ||
|
||
public addNotActions(...notactions: string[]) { | ||
this.notaction.push(...notactions); | ||
} | ||
|
||
// | ||
// Principal | ||
// | ||
|
@@ -98,6 +106,10 @@ export class PolicyStatement { | |
this.resource.push(...arns); | ||
} | ||
|
||
public addNotResources(...arns: string[]) { | ||
this.notresource.push(...arns); | ||
} | ||
|
||
/** | ||
* Adds a ``"*"`` resource to this statement. | ||
*/ | ||
|
@@ -142,10 +154,12 @@ export class PolicyStatement { | |
public toStatementJson(): any { | ||
return noUndef({ | ||
Action: _norm(this.action), | ||
NotAction: _norm(this.notaction), | ||
Condition: _norm(this.condition), | ||
Effect: _norm(this.effect), | ||
Principal: _normPrincipal(this.principal), | ||
Resource: _norm(this.resource), | ||
NotResource: _norm(this.notresource), | ||
Sid: _norm(this.sid), | ||
}); | ||
|
||
|
@@ -229,6 +243,13 @@ export interface PolicyStatementProps { | |
*/ | ||
readonly actions?: string[]; | ||
|
||
/** | ||
* List of not actions to add to the statement | ||
* | ||
* @default - no actions | ||
*/ | ||
readonly notactions?: string[]; | ||
|
||
/** | ||
* List of principals to add to the statement | ||
* | ||
|
@@ -239,10 +260,17 @@ export interface PolicyStatementProps { | |
/** | ||
* Resource ARNs to add to the statement | ||
* | ||
* @default - no principals | ||
* @default - no resources | ||
*/ | ||
readonly resources?: string[]; | ||
|
||
/** | ||
* NotResource ARNs to add to the statement | ||
* | ||
* @default - no resources | ||
*/ | ||
readonly notresources?: string[]; | ||
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. Shouldn't this be called 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. You are right, it should have been. 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. You want to change this before v1.5.0? 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. Hell yes :) 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. I can quickly open a PR to fix the casing, The check against combining 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. OK you did it already :) |
||
|
||
/** | ||
* Conditions to add to the statement | ||
* | ||
|
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.
Shouldn't this be called
notActions
? Camel case? @eladbThere 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.
You are right, it should have been.