From 140268b9298c6b078a37e078ee9756977d0c82e2 Mon Sep 17 00:00:00 2001 From: Mitch Lloyd Date: Wed, 8 May 2019 19:01:35 -0700 Subject: [PATCH] Allow CompositePrincipal construction with spread --- packages/@aws-cdk/aws-iam/lib/policy-document.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/@aws-cdk/aws-iam/lib/policy-document.ts b/packages/@aws-cdk/aws-iam/lib/policy-document.ts index 7ebf7565dc6a6..ea315a19d5186 100644 --- a/packages/@aws-cdk/aws-iam/lib/policy-document.ts +++ b/packages/@aws-cdk/aws-iam/lib/policy-document.ts @@ -287,11 +287,13 @@ export class CompositePrincipal extends PrincipalBase { public readonly assumeRoleAction: string; private readonly principals = new Array(); - constructor(principal: PrincipalBase, ...additionalPrincipals: PrincipalBase[]) { + constructor(...principals: PrincipalBase[]) { super(); - this.assumeRoleAction = principal.assumeRoleAction; - this.addPrincipals(principal); - this.addPrincipals(...additionalPrincipals); + if (principals.length === 0) { + throw new Error('CompositePrincipals must be constructed with at least 1 Principal but none were passed.') + } + this.assumeRoleAction = principals[0].assumeRoleAction; + this.addPrincipals(...principals); } public addPrincipals(...principals: PrincipalBase[]): this {