Skip to content

Commit d301b8e

Browse files
committed
refactor: support s3 key resolve with jsonata value and fallback to wildcard
1 parent 4e5efd6 commit d301b8e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/deploy/stepFunctions/compileIamRole.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ const { getArnPartition } = require('../../utils/arn');
88

99
const logger = require('../../utils/logger');
1010

11+
/**
12+
* Check if a value is a JSONata value template
13+
* e.g {% $.some.path %}
14+
*/
15+
function isJsonataValueTemplate(value) {
16+
return typeof value === 'string' && value.trim().startsWith('{%') && value.trim().endsWith('}');
17+
}
18+
1119
function getTaskStates(states, stateMachineName) {
1220
return _.flatMap(states, (state) => {
1321
switch (state.Type) {
@@ -657,7 +665,13 @@ function resolveS3BucketReferences(bucket, resources) {
657665
function getS3ObjectPermissions(action, state) {
658666
// Use the helper so both Arguments (JSONata) and Parameters (JSONPath) are supported
659667
const bucket = getParameterOrArgument(state, 'Bucket') || '*';
660-
const key = getParameterOrArgument(state, 'Key') || '*';
668+
let key = getParameterOrArgument(state, 'Key') || '*';
669+
if (isJsonataValueTemplate(key)) {
670+
console.warn(
671+
"Warning: When using JSONata, S3 object permissions will be given for all objects in the bucket"
672+
);
673+
key = "*";
674+
}
661675
const prefix = getParameterOrArgument(state, 'Prefix');
662676
let arn;
663677

0 commit comments

Comments
 (0)