@@ -3,6 +3,7 @@ import { CedarPolicyItem } from './cedar-policy-items';
33
44interface ParsedPermitStatement {
55 action : string | null ;
6+ actions : string [ ] | null ;
67 resourceType : string | null ;
78 resourceId : string | null ;
89 isWildcard : boolean ;
@@ -225,12 +226,18 @@ function extractPermitStatements(policyText: string): ParsedPermitStatement[] {
225226 }
226227 }
227228
228- return results ;
229+ return results . flatMap ( expandActionIn ) ;
230+ }
231+
232+ function expandActionIn ( stmt : ParsedPermitStatement ) : ParsedPermitStatement [ ] {
233+ if ( ! stmt . actions || stmt . actions . length === 0 ) return [ stmt ] ;
234+ return stmt . actions . map ( ( action ) => ( { ...stmt , action, actions : null } ) ) ;
229235}
230236
231237function parsePermitBody ( body : string ) : ParsedPermitStatement {
232238 const result : ParsedPermitStatement = {
233239 action : null ,
240+ actions : null ,
234241 resourceType : null ,
235242 resourceId : null ,
236243 isWildcard : false ,
@@ -240,9 +247,14 @@ function parsePermitBody(body: string): ParsedPermitStatement {
240247 if ( actionMatch ) {
241248 result . action = actionMatch [ 1 ] ;
242249 } else {
243- const actionClause = body . match ( / , \s * ( a c t i o n ) \s * , / ) ;
244- if ( actionClause ) {
245- result . isWildcard = true ;
250+ const actionInMatch = body . match ( / a c t i o n \s + i n \s * \[ ( [ ^ \] ] + ) \] / ) ;
251+ if ( actionInMatch ) {
252+ result . actions = [ ...actionInMatch [ 1 ] . matchAll ( / R o c k e t A d m i n : : A c t i o n : : " ( [ ^ " ] + ) " / g) ] . map ( ( m ) => m [ 1 ] ) ;
253+ } else {
254+ const actionClause = body . match ( / , \s * ( a c t i o n ) \s * , / ) ;
255+ if ( actionClause ) {
256+ result . isWildcard = true ;
257+ }
246258 }
247259 }
248260
@@ -261,7 +273,7 @@ function parsePermitBody(body: string): ParsedPermitStatement {
261273}
262274
263275function extractResourceSuffix ( resourceId : string | null , connectionId : string ) : string | null {
264- if ( ! resourceId ) return null ;
276+ if ( ! resourceId ) return '*' ;
265277 const prefix = `${ connectionId } /` ;
266278 if ( resourceId . startsWith ( prefix ) ) {
267279 return resourceId . slice ( prefix . length ) ;
0 commit comments