@@ -3,14 +3,15 @@ import { CustomerManagedEncryptionConfiguration } from './customer-managed-key-e
33import { EncryptionConfiguration } from './encryption-configuration' ;
44import { buildEncryptionConfiguration } from './private/util' ;
55import { StateGraph } from './state-graph' ;
6+ import { StateMachineGrants } from './state-machine-grants' ;
67import { StatesMetrics } from './stepfunctions-canned-metrics.generated' ;
7- import { CfnStateMachine } from './stepfunctions.generated' ;
8+ import { CfnStateMachine , IStateMachineRef , StateMachineReference } from './stepfunctions.generated' ;
89import { IChainable , QueryLanguage } from './types' ;
910import * as cloudwatch from '../../aws-cloudwatch' ;
1011import * as iam from '../../aws-iam' ;
1112import * as logs from '../../aws-logs' ;
1213import * as s3_assets from '../../aws-s3-assets' ;
13- import { Arn , ArnFormat , Duration , IResource , RemovalPolicy , Resource , Stack , Token , ValidationError } from '../../core' ;
14+ import { ArnFormat , Duration , IResource , RemovalPolicy , Resource , Stack , Token , ValidationError } from '../../core' ;
1415import { addConstructMetadata , MethodMetadata } from '../../core/lib/metadata-resource' ;
1516import { propertyInjectable } from '../../core/lib/prop-injectable' ;
1617
@@ -215,87 +216,53 @@ abstract class StateMachineBase extends Resource implements IStateMachine {
215216 */
216217 public abstract readonly grantPrincipal : iam . IPrincipal ;
217218
219+ /**
220+ * Collection of grant methods for a StateMachine
221+ */
222+ public grants = StateMachineGrants . _fromStateMachine ( this ) ;
223+
224+ public get stateMachineRef ( ) : StateMachineReference {
225+ return {
226+ stateMachineArn : this . stateMachineArn ,
227+ } ;
228+ }
229+
218230 /**
219231 * Grant the given identity permissions to start an execution of this state
220232 * machine.
221233 */
222234 public grantStartExecution ( identity : iam . IGrantable ) : iam . Grant {
223- return iam . Grant . addToPrincipal ( {
224- grantee : identity ,
225- actions : [ 'states:StartExecution' ] ,
226- resourceArns : [ this . stateMachineArn ] ,
227- } ) ;
235+ return this . grants . startExecution ( identity ) ;
228236 }
229237
230238 /**
231239 * Grant the given identity permissions to start a synchronous execution of
232240 * this state machine.
233241 */
234242 public grantStartSyncExecution ( identity : iam . IGrantable ) : iam . Grant {
235- return iam . Grant . addToPrincipal ( {
236- grantee : identity ,
237- actions : [ 'states:StartSyncExecution' ] ,
238- resourceArns : [ this . stateMachineArn ] ,
239- } ) ;
243+ return this . grants . startSyncExecution ( identity ) ;
240244 }
241245
242246 /**
243247 * Grant the given identity permissions to read results from state
244248 * machine.
245249 */
246250 public grantRead ( identity : iam . IGrantable ) : iam . Grant {
247- iam . Grant . addToPrincipal ( {
248- grantee : identity ,
249- actions : [
250- 'states:ListExecutions' ,
251- 'states:ListStateMachines' ,
252- ] ,
253- resourceArns : [ this . stateMachineArn ] ,
254- } ) ;
255- iam . Grant . addToPrincipal ( {
256- grantee : identity ,
257- actions : [
258- 'states:DescribeExecution' ,
259- 'states:DescribeStateMachineForExecution' ,
260- 'states:GetExecutionHistory' ,
261- ] ,
262- resourceArns : [ `${ this . executionArn ( ) } :*` ] ,
263- } ) ;
264- return iam . Grant . addToPrincipal ( {
265- grantee : identity ,
266- actions : [
267- 'states:ListActivities' ,
268- 'states:DescribeStateMachine' ,
269- 'states:DescribeActivity' ,
270- ] ,
271- resourceArns : [ '*' ] ,
272- } ) ;
251+ return this . grants . read ( identity ) ;
273252 }
274253
275254 /**
276255 * Grant the given identity task response permissions on a state machine
277256 */
278257 public grantTaskResponse ( identity : iam . IGrantable ) : iam . Grant {
279- return iam . Grant . addToPrincipal ( {
280- grantee : identity ,
281- actions : [
282- 'states:SendTaskSuccess' ,
283- 'states:SendTaskFailure' ,
284- 'states:SendTaskHeartbeat' ,
285- ] ,
286- resourceArns : [ this . stateMachineArn ] ,
287- } ) ;
258+ return this . grants . taskResponse ( identity ) ;
288259 }
289260
290261 /**
291262 * Grant the given identity permissions on all executions of the state machine
292263 */
293264 public grantExecution ( identity : iam . IGrantable , ...actions : string [ ] ) {
294- return iam . Grant . addToPrincipal ( {
295- grantee : identity ,
296- actions,
297- resourceArns : [ `${ this . executionArn ( ) } :*` ] ,
298- } ) ;
265+ return this . grants . execution ( identity , ...actions ) ;
299266 }
300267
301268 /**
@@ -309,11 +276,7 @@ abstract class StateMachineBase extends Resource implements IStateMachine {
309276 * Grant the given identity custom permissions
310277 */
311278 public grant ( identity : iam . IGrantable , ...actions : string [ ] ) : iam . Grant {
312- return iam . Grant . addToPrincipal ( {
313- grantee : identity ,
314- actions,
315- resourceArns : [ this . stateMachineArn ] ,
316- } ) ;
279+ return this . grants . actions ( identity , ...actions ) ;
317280 }
318281
319282 /**
@@ -395,18 +358,6 @@ abstract class StateMachineBase extends Resource implements IStateMachine {
395358 return this . cannedMetric ( StatesMetrics . executionTimeAverage , props ) ;
396359 }
397360
398- /**
399- * Returns the pattern for the execution ARN's of the state machine
400- */
401- private executionArn ( ) : string {
402- return Stack . of ( this ) . formatArn ( {
403- resource : 'execution' ,
404- service : 'states' ,
405- resourceName : Arn . split ( this . stateMachineArn , ArnFormat . COLON_RESOURCE_NAME ) . resourceName ,
406- arnFormat : ArnFormat . COLON_RESOURCE_NAME ,
407- } ) ;
408- }
409-
410361 private cannedMetric (
411362 fn : ( dims : { StateMachineArn : string } ) => cloudwatch . MetricProps ,
412363 props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
@@ -657,7 +608,7 @@ export class StateMachine extends StateMachineBase {
657608/**
658609 * A State Machine
659610 */
660- export interface IStateMachine extends IResource , iam . IGrantable {
611+ export interface IStateMachine extends IResource , iam . IGrantable , IStateMachineRef {
661612 /**
662613 * The ARN of the state machine
663614 * @attribute
0 commit comments