Skip to content

Commit

Permalink
Tighten substitution pattern for Fn::Sub (#842)
Browse files Browse the repository at this point in the history
CloudFormation variables can be parameter names, resource logical IDs
or resource attributes.

* Parameter names: can be alphanumeric or pseudo-parameters, which can
  be prefixed with "AWS::"
* Resource logical IDs: can be alphanumeric.
* Resource attributes: specified as resourceLogicalId.attributeName,
  where attributeName is also alphanumeric.
  • Loading branch information
gosar authored Jun 25, 2021
1 parent 607bf92 commit fd5731f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final class CloudFormationSubstitution implements ApiGatewayMapper {

private static final Logger LOGGER = Logger.getLogger(CloudFormationSubstitution.class.getName());
private static final String SUBSTITUTION_KEY = "Fn::Sub";
private static final Pattern SUBSTITUTION_PATTERN = Pattern.compile("\\$\\{.+}");
private static final Pattern SUBSTITUTION_PATTERN = Pattern.compile("\\$\\{[A-Za-z0-9.:]+}");

/**
* This is a hardcoded list of paths that are known to contain ARNs or identifiers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ public void pluginCanBeDisabled() {
.config(config)
.convertToNode(model);

Node.assertEquals(expected, actual);
Node.assertEquals(actual, expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
"smithy.api#http": {
"uri": "/foo",
"method": "GET"
},
"aws.apigateway#integration": {
"httpMethod": "POST",
"payloadFormatVersion": "2.0",
"type": "aws_proxy",
"uri": "arn:${Token[AWS.Partition.9]}:apigateway:us-east-1:lambda:path/2015-03-31/functions/${Token[TOKEN.108]}/invocations"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"200": {
"description": "MyOperation response"
}
},
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"payloadFormatVersion": "2.0",
"type": "aws_proxy",
"uri": "arn:${Token[AWS.Partition.9]}:apigateway:us-east-1:lambda:path/2015-03-31/functions/${Token[TOKEN.108]}/invocations"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"200": {
"description": "MyOperation response"
}
},
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"payloadFormatVersion": "2.0",
"type": "aws_proxy",
"uri": "arn:${Token[AWS.Partition.9]}:apigateway:us-east-1:lambda:path/2015-03-31/functions/${Token[TOKEN.108]}/invocations"
}
}
}
Expand Down

0 comments on commit fd5731f

Please sign in to comment.