Skip to content

Commit

Permalink
Reintroduce the Condition type
Browse files Browse the repository at this point in the history
This reverts commit ffc2bdc.

Also adds the required ignores for these "breaking" changes to be
accepted, and fixes the one remaining union type.
  • Loading branch information
zakwalters committed Apr 4, 2020
1 parent e200f8d commit 9fad94c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions allowed-breaking-changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ change-return-type:@aws-cdk/aws-lambda-destinations.LambdaDestination.bind
change-return-type:@aws-cdk/aws-lambda-destinations.SnsDestination.bind
change-return-type:@aws-cdk/aws-lambda-destinations.SqsDestination.bind
removed:@aws-cdk/cdk-assets-schema.DockerImageDestination.imageUri
incompatible-argument:@aws-cdk/aws-iam.FederatedPrincipal.<initializer>
incompatible-argument:@aws-cdk/aws-iam.PolicyStatement.addCondition
incompatible-argument:@aws-cdk/aws-iam.PolicyStatement.addConditions
incompatible-argument:@aws-cdk/aws-iam.PolicyStatement.addFederatedPrincipal
incompatible-argument:@aws-cdk/aws-iam.PrincipalPolicyFragment.<initializer>
10 changes: 8 additions & 2 deletions packages/@aws-cdk/aws-iam/lib/policy-statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export class PolicyStatement {
/**
* Add a condition to the Policy
*/
public addCondition(key: string, value: any) {
public addCondition(key: string, value: Condition) {
const existingValue = this.condition[key];
this.condition[key] = existingValue ? { ...existingValue, ...value } : value;
}
Expand Down Expand Up @@ -303,6 +303,12 @@ export enum Effect {
DENY = 'Deny',
}

/**
* Condition for when an IAM policy is in effect. Maps from the keys in a request's context to
* a string value or array of string values. See the Conditions interface for more details.
*/
export type Condition = Record<string, any>;

/**
* Conditions for when an IAM Policy is in effect, specified in the following structure:
*
Expand All @@ -313,7 +319,7 @@ export enum Effect {
* For more information, including which operators are supported, see [the IAM
* documentation](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html).
*/
export type Conditions = Record<string, any>;
export type Conditions = Record<string, Condition>;

/**
* Interface for creating a policy statement
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-iam/lib/principals.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as cdk from '@aws-cdk/core';
import { Default, RegionInfo } from '@aws-cdk/region-info';
import { Conditions, PolicyStatement } from './policy-statement';
import { Condition, Conditions, PolicyStatement } from './policy-statement';
import { mergePrincipal } from './util';

/**
Expand Down Expand Up @@ -123,7 +123,7 @@ export class PrincipalWithConditions implements IPrincipal {
/**
* Add a condition to the principal
*/
public addCondition(key: string, value: { [key: string]: any }) {
public addCondition(key: string, value: Condition) {
const existingValue = this.conditions[key];
this.conditions[key] = existingValue ? { ...existingValue, ...value } : value;
}
Expand Down

0 comments on commit 9fad94c

Please sign in to comment.