Skip to content

Commit dc2fe15

Browse files
authored
chore: replace a real IRole with a type intersection (#35885)
This re-applies #35770 (which was reverted in #35871). Contains an upgrade to a fixed version of `jsii-pacmak`. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 94d7e34 commit dc2fe15

File tree

8 files changed

+98
-43
lines changed

8 files changed

+98
-43
lines changed

allowed-breaking-changes.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,3 @@ removed:aws-cdk-lib.lambda_layer_kubectl.KubectlLayer
966966
# Fixing the JsonSchema interface to be consistent with JSON Schema spec
967967
changed-type:aws-cdk-lib.aws_apigateway.JsonSchema.additionalItems
968968
strengthened:aws-cdk-lib.aws_apigateway.JsonSchema
969-
970-
# Revert a failing change
971-
strengthened:aws-cdk-lib.aws_stepfunctions.StateMachineProps

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
"fs-extra": "^9.1.0",
2727
"graceful-fs": "^4.2.11",
2828
"jest-junit": "^13.2.0",
29-
"jsii-diff": "1.116.0",
30-
"jsii-pacmak": "1.116.0",
31-
"jsii-reflect": "1.116.0",
29+
"jsii-diff": "1.118.0",
30+
"jsii-pacmak": "1.118.0",
31+
"jsii-reflect": "1.118.0",
3232
"lerna": "^8.2.4",
3333
"nx": "^20",
3434
"semver": "^7.7.2",

packages/aws-cdk-lib/aws-stepfunctions/lib/state-machine.ts

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export interface StateMachineProps {
117117
*
118118
* @default A role is automatically created
119119
*/
120-
readonly role?: iam.IRole;
120+
readonly role?: iam.IRoleRef & iam.IGrantable;
121121

122122
/**
123123
* Maximum run time for this state machine
@@ -427,11 +427,6 @@ export class StateMachine extends StateMachineBase {
427427
*/
428428
public static readonly PROPERTY_INJECTION_ID: string = 'aws-cdk-lib.aws-stepfunctions.StateMachine';
429429

430-
/**
431-
* Execution role of this state machine
432-
*/
433-
public readonly role: iam.IRole;
434-
435430
/**
436431
* The name of the state machine
437432
* @attribute
@@ -455,6 +450,11 @@ export class StateMachine extends StateMachineBase {
455450
*/
456451
public readonly stateMachineRevisionId: string;
457452

453+
/**
454+
* Execution role of this state machine
455+
*/
456+
private readonly _role: iam.IRoleRef & iam.IGrantable;
457+
458458
constructor(scope: Construct, id: string, props: StateMachineProps) {
459459
super(scope, id, {
460460
physicalName: props.stateMachineName,
@@ -476,7 +476,7 @@ export class StateMachine extends StateMachineBase {
476476
this.validateLogOptions(props.logs);
477477
}
478478

479-
this.role = props.role || new iam.Role(this, 'Role', {
479+
this._role = props.role || new iam.Role(this, 'Role', {
480480
assumedBy: new iam.ServicePrincipal('states.amazonaws.com'),
481481
});
482482

@@ -494,7 +494,7 @@ export class StateMachine extends StateMachineBase {
494494
}
495495

496496
if (props.encryptionConfiguration instanceof CustomerManagedEncryptionConfiguration) {
497-
this.role.addToPrincipalPolicy(new iam.PolicyStatement({
497+
this._role.grantPrincipal.addToPrincipalPolicy(new iam.PolicyStatement({
498498
effect: iam.Effect.ALLOW,
499499
actions: [
500500
'kms:Decrypt', 'kms:GenerateDataKey',
@@ -513,7 +513,7 @@ export class StateMachine extends StateMachineBase {
513513
}));
514514

515515
if (props.logs && props.logs.level !== LogLevel.OFF) {
516-
this.role.addToPrincipalPolicy(new iam.PolicyStatement({
516+
this._role.grantPrincipal.addToPrincipalPolicy(new iam.PolicyStatement({
517517
effect: iam.Effect.ALLOW,
518518
actions: [
519519
'kms:GenerateDataKey',
@@ -540,10 +540,10 @@ export class StateMachine extends StateMachineBase {
540540
const resource = new CfnStateMachine(this, 'Resource', {
541541
stateMachineName: this.physicalName,
542542
stateMachineType: props.stateMachineType ?? undefined,
543-
roleArn: this.role.roleArn,
543+
roleArn: this._role.roleRef.roleArn,
544544
loggingConfiguration: props.logs ? this.buildLoggingConfiguration(props.logs) : undefined,
545545
tracingConfiguration: this.buildTracingConfiguration(props.tracingEnabled),
546-
...definitionBody.bind(this, this.role, props, graph),
546+
...definitionBody.bind(this, this._role.grantPrincipal, props, graph),
547547
definitionSubstitutions: props.definitionSubstitutions,
548548
encryptionConfiguration: buildEncryptionConfiguration(props.encryptionConfiguration),
549549
});
@@ -569,15 +569,27 @@ export class StateMachine extends StateMachineBase {
569569
* The principal this state machine is running as
570570
*/
571571
public get grantPrincipal() {
572-
return this.role.grantPrincipal;
572+
return this._role.grantPrincipal;
573+
}
574+
575+
/**
576+
* Execution role of this state machine
577+
*
578+
* Will throw if the Role object that was given does not implement IRole
579+
*/
580+
public get role(): iam.IRole {
581+
if (!isIRole(this._role)) {
582+
throw new ValidationError(`The role given to this StateMachine is not an IRole, but ${this._role.constructor.name}`, this);
583+
}
584+
return this._role;
573585
}
574586

575587
/**
576588
* Add the given statement to the role's policy
577589
*/
578590
@MethodMetadata()
579591
public addToRolePolicy(statement: iam.PolicyStatement) {
580-
this.role.addToPrincipalPolicy(statement);
592+
this._role.grantPrincipal.addToPrincipalPolicy(statement);
581593
}
582594

583595
private validateStateMachineName(stateMachineName: string) {
@@ -846,3 +858,9 @@ export class ChainDefinitionBody extends DefinitionBody {
846858
};
847859
}
848860
}
861+
862+
function isIRole(x: iam.IRoleRef): x is iam.IRole {
863+
const xx = x as iam.IRole;
864+
return (!!xx.addManagedPolicy && !!xx.addToPrincipalPolicy && !!xx.assumeRoleAction && !!xx.attachInlinePolicy
865+
&& !!xx.grant && !!xx.policyFragment);
866+
}

packages/awslint/bin/awslint.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
/* eslint-disable no-console */
33
import * as child_process from 'child_process';
44
import * as path from 'path';
5+
import { JsiiFeature } from '@jsii/spec';
56
import * as chalk from 'chalk';
67
import * as fs from 'fs-extra';
78
import * as reflect from 'jsii-reflect';
89
import * as yargs from 'yargs';
910
import { ALL_RULES_LINTER, DiagnosticLevel, RuleFilterSet } from '../lib';
1011

12+
const FEATURES: JsiiFeature[] = ['intersection-types'];
13+
1114
let stackTrace = false;
1215

1316
async function main() {
@@ -247,7 +250,7 @@ main().catch(e => {
247250

248251
async function loadModule(dir: string) {
249252
const ts = new reflect.TypeSystem();
250-
await ts.load(dir, { validate: false }); // Don't validate to save 66% of execution time (20s vs 1min).
253+
await ts.load(dir, { validate: false, supportedFeatures: FEATURES }); // Don't validate to save 66% of execution time (20s vs 1min).
251254
// We run 'awslint' during build time, assemblies are guaranteed to be ok.
252255

253256
// We won't load any more assemblies. Lock the typesystem to benefit from performance improvements.

packages/awslint/lib/rules/api.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ apiLinter.add({
139139
return;
140140
}
141141

142+
if (type.intersectionOfTypes) {
143+
// Type intersections are okay
144+
return;
145+
}
146+
142147
throw new Error(`invalid type reference: ${type.toString()}`);
143148
}
144149
},

scripts/run-rosetta.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ time $ROSETTA extract \
7373

7474
if $infuse; then
7575
echo "💎 Generating synthetic examples for the remainder" >&2
76-
time npx cdk-generate-synthetic-examples@^0.1.292 \
76+
time npx cdk-generate-synthetic-examples \
7777
$(cat $jsii_pkgs_file)
7878

7979
time $ROSETTA extract \

tools/@aws-cdk/cdk-build-tools/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
"jest-junit": "^13.2.0",
6464
"jsii": "~5.9.8",
6565
"jsii-rosetta": "~5.9.9",
66-
"jsii-pacmak": "1.116.0",
67-
"jsii-reflect": "1.116.0",
66+
"jsii-pacmak": "1.118.0",
67+
"jsii-reflect": "1.118.0",
6868
"markdownlint-cli": "^0.45.0",
6969
"nyc": "^15.1.0",
7070
"semver": "^7.7.2",

yarn.lock

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3518,6 +3518,14 @@
35183518
chalk "^4.1.2"
35193519
semver "^7.7.2"
35203520

3521+
3522+
version "1.118.0"
3523+
resolved "https://registry.npmjs.org/@jsii/check-node/-/check-node-1.118.0.tgz#0be4fef43c7058764e3b4d146c6fbc80306de6bd"
3524+
integrity sha512-8IaXtUO6oq3Dmi9rxXqsBRnKxqbe0OARGt4tw46Li7kR5/GXE/DBGPKZ2rOvi2CekOh8b3VGBU+wd84RQciTAA==
3525+
dependencies:
3526+
chalk "^4.1.2"
3527+
semver "^7.7.2"
3528+
35213529
35223530
version "1.114.1"
35233531
resolved "https://registry.npmjs.org/@jsii/spec/-/spec-1.114.1.tgz#9c064d57f062d913bcfda25b5496bdf4c9c95c46"
@@ -3539,6 +3547,13 @@
35393547
dependencies:
35403548
ajv "^8.17.1"
35413549

3550+
3551+
version "1.118.0"
3552+
resolved "https://registry.npmjs.org/@jsii/spec/-/spec-1.118.0.tgz#66d6da3089e002ee3ee89dcc6e9d284a039acf94"
3553+
integrity sha512-aVe535/sN1EW88DYiEO3r0gqkKJ7ob0yfWC8+c1GVEayAecuvBjmwzzc7oDIIOthZ7PT3OBJ2xPqGqtbCyR3Uw==
3554+
dependencies:
3555+
ajv "^8.17.1"
3556+
35423557
35433558
version "8.2.4"
35443559
resolved "https://registry.npmjs.org/@lerna/create/-/create-8.2.4.tgz#59a050f58681e9236db38cc5bcc6986ae79d1389"
@@ -6654,10 +6669,10 @@ code-block-writer@^13.0.3:
66546669
resolved "https://registry.npmjs.org/code-block-writer/-/code-block-writer-13.0.3.tgz#90f8a84763a5012da7af61319dd638655ae90b5b"
66556670
integrity sha512-Oofo0pq3IKnsFtuHqSF7TqBfr71aeyZDVJ0HpmqB7FBM2qEigL0iPONSCZSO9pE9dZTAxANe5XHG9Uy0YMv8cg==
66566671

6657-
codemaker@^1.116.0:
6658-
version "1.116.0"
6659-
resolved "https://registry.npmjs.org/codemaker/-/codemaker-1.116.0.tgz#1fccbcb720f987ac3d21b0fb92ad6e749eedb6b3"
6660-
integrity sha512-o23BKz+Y0Yam/czEbe3UAXVqSY4HFKgUYTffx3YW6yPtAVSX0d50BgIU0RxCUGIWmFD9Go3tXqraRDpo7TxMLg==
6672+
codemaker@^1.118.0:
6673+
version "1.118.0"
6674+
resolved "https://registry.npmjs.org/codemaker/-/codemaker-1.118.0.tgz#2587611d167bdece0beff9f2748b2baae04c655b"
6675+
integrity sha512-d6ddG2oKNwkYBRJtsdEaKbJLBaxZJO0ImSG89wi6j5y549olTB3ERsqGGRZ47HlRuaVpkbOXnG/kb8I6ELxtMA==
66616676
dependencies:
66626677
camelcase "^6.3.0"
66636678
decamelize "^5.0.1"
@@ -10064,37 +10079,37 @@ jsesc@^3.0.2:
1006410079
resolved "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz#74d335a234f67ed19907fdadfac7ccf9d409825d"
1006510080
integrity sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA==
1006610081

10067-
jsii-diff@1.116.0:
10068-
version "1.116.0"
10069-
resolved "https://registry.npmjs.org/jsii-diff/-/jsii-diff-1.116.0.tgz#0445d7492e42f7b27c7c7e08703181a3cbcca5cf"
10070-
integrity sha512-6t7MJe9gWo/vnkQrHNLlOdOO7ZRnqqGoC2uk8M1C2Gc/Yc8mBuyQhF9Fj0+hPmChURI5cqHsFatFce9P79fS0Q==
10082+
jsii-diff@1.118.0:
10083+
version "1.118.0"
10084+
resolved "https://registry.npmjs.org/jsii-diff/-/jsii-diff-1.118.0.tgz#d91be0448a29dc0aacca0b2350d20186dfb1243d"
10085+
integrity sha512-Po0jJU5ib3G7IZ411OZbILyTFcJ1veb1O1NK1OSg2iejquhEnViNhrZSwEgbCWIZyfu+BKTgrW7rG3KYgPgAhA==
1007110086
dependencies:
10072-
"@jsii/check-node" "1.116.0"
10073-
"@jsii/spec" "1.116.0"
10087+
"@jsii/check-node" "1.118.0"
10088+
"@jsii/spec" "1.118.0"
1007410089
fs-extra "^10.1.0"
10075-
jsii-reflect "^1.116.0"
10090+
jsii-reflect "^1.118.0"
1007610091
log4js "^6.9.1"
1007710092
yargs "^17.7.2"
1007810093

10079-
jsii-pacmak@1.116.0:
10080-
version "1.116.0"
10081-
resolved "https://registry.npmjs.org/jsii-pacmak/-/jsii-pacmak-1.116.0.tgz#c94d0141d56dbd4f3e9c0d6a5234a9a72ab28215"
10082-
integrity sha512-X3UQouUnp05/CbtZzORrBIDQBb26ChX6Ms5q3dXxsJyk5/DEJaCkd6pAnU3wiya7Tsrd8K09mSiuseMzxFvs8Q==
10094+
jsii-pacmak@1.118.0:
10095+
version "1.118.0"
10096+
resolved "https://registry.npmjs.org/jsii-pacmak/-/jsii-pacmak-1.118.0.tgz#a4ad053535ffc4142a544c797272082e98289801"
10097+
integrity sha512-RY7l//WI8G3IN2u1R8S6rFDT2jcNwjiR3RWyWu6NtcPchn+V/8aqX+8j1PmyRGfop8qAKcPc0AL3rAx2OmcmAw==
1008310098
dependencies:
10084-
"@jsii/check-node" "1.116.0"
10085-
"@jsii/spec" "1.116.0"
10099+
"@jsii/check-node" "1.118.0"
10100+
"@jsii/spec" "1.118.0"
1008610101
clone "^2.1.2"
10087-
codemaker "^1.116.0"
10102+
codemaker "^1.118.0"
1008810103
commonmark "^0.31.2"
1008910104
escape-string-regexp "^4.0.0"
1009010105
fs-extra "^10.1.0"
10091-
jsii-reflect "^1.116.0"
10106+
jsii-reflect "^1.118.0"
1009210107
semver "^7.7.2"
1009310108
spdx-license-list "^6.10.0"
1009410109
xmlbuilder "^15.1.1"
1009510110
yargs "^17.7.2"
1009610111

10097-
[email protected], jsii-reflect@^1.116.0:
10112+
1009810113
version "1.116.0"
1009910114
resolved "https://registry.npmjs.org/jsii-reflect/-/jsii-reflect-1.116.0.tgz#2dda056b311b9b7eed49ac27c45743f64f0057d7"
1010010115
integrity sha512-ZIHznFUMHQinqNLu48JibrnB0O0EeINCUgtkgV+SqEN7wsM1kxT3SBLHEbCQqPzB5ZsQzrdl9JW1vMi14/YqGA==
@@ -10106,6 +10121,18 @@ [email protected], jsii-reflect@^1.116.0:
1010610121
oo-ascii-tree "^1.116.0"
1010710122
yargs "^17.7.2"
1010810123

10124+
[email protected], jsii-reflect@^1.118.0:
10125+
version "1.118.0"
10126+
resolved "https://registry.npmjs.org/jsii-reflect/-/jsii-reflect-1.118.0.tgz#ff33ffba10090e5903dd9ddb2a5c6252c1fbf1c3"
10127+
integrity sha512-P3iASRGS8j87uT66MZ2jQvxPZRLdXBMoSEBECn3+krKCauaZntymXm/iQmWCgTnpt43cwz+eYkY1D3KA1sGjzA==
10128+
dependencies:
10129+
"@jsii/check-node" "1.118.0"
10130+
"@jsii/spec" "1.118.0"
10131+
chalk "^4"
10132+
fs-extra "^10.1.0"
10133+
oo-ascii-tree "^1.118.0"
10134+
yargs "^17.7.2"
10135+
1010910136
jsii-reflect@^1.115.0:
1011010137
version "1.115.0"
1011110138
resolved "https://registry.npmjs.org/jsii-reflect/-/jsii-reflect-1.115.0.tgz#debe523fa2de0ba020d54d41a2f7b0e0bc8ef048"
@@ -11752,6 +11779,11 @@ oo-ascii-tree@^1.116.0:
1175211779
resolved "https://registry.npmjs.org/oo-ascii-tree/-/oo-ascii-tree-1.116.0.tgz#2bd95d7de16b842289e01bd83e29f93ea463eaf5"
1175311780
integrity sha512-GI0n8coDIoZPywmZp5l2qPO1tqZxN40/tFPYBxWD2vpPeciKiB/nxZ7blDjp97ejxtmdkNouvAmtg4nCYgZihg==
1175411781

11782+
oo-ascii-tree@^1.118.0:
11783+
version "1.118.0"
11784+
resolved "https://registry.npmjs.org/oo-ascii-tree/-/oo-ascii-tree-1.118.0.tgz#1d222c348358f96362c6b65f766f2af39a42bb9c"
11785+
integrity sha512-ATGzZ+AxeHuGdNlniQNn9xvaVDo8IfET84Xep0XS33KXr19EZum7VpzBuKtcfNM/NQ7uk1d4ePXMqyiHeA9Dxw==
11786+
1175511787
open@^8.4.0:
1175611788
version "8.4.2"
1175711789
resolved "https://registry.npmjs.org/open/-/open-8.4.2.tgz#5b5ffe2a8f793dcd2aad73e550cb87b59cb084f9"

0 commit comments

Comments
 (0)