Skip to content

Commit fd5731f

Browse files
authored
Tighten substitution pattern for Fn::Sub (smithy-lang#842)
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.
1 parent 607bf92 commit fd5731f

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed

smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/CloudFormationSubstitution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final class CloudFormationSubstitution implements ApiGatewayMapper {
4545

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

5050
/**
5151
* This is a hardcoded list of paths that are known to contain ARNs or identifiers

smithy-aws-apigateway-openapi/src/test/java/software/amazon/smithy/aws/apigateway/openapi/CloudFormationSubstitutionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ public void pluginCanBeDisabled() {
6969
.config(config)
7070
.convertToNode(model);
7171

72-
Node.assertEquals(expected, actual);
72+
Node.assertEquals(actual, expected);
7373
}
7474
}

smithy-aws-apigateway-openapi/src/test/resources/software/amazon/smithy/aws/apigateway/openapi/cloudformation-substitutions.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
"smithy.api#http": {
2626
"uri": "/foo",
2727
"method": "GET"
28+
},
29+
"aws.apigateway#integration": {
30+
"httpMethod": "POST",
31+
"payloadFormatVersion": "2.0",
32+
"type": "aws_proxy",
33+
"uri": "arn:${Token[AWS.Partition.9]}:apigateway:us-east-1:lambda:path/2015-03-31/functions/${Token[TOKEN.108]}/invocations"
2834
}
2935
}
3036
}

smithy-aws-apigateway-openapi/src/test/resources/software/amazon/smithy/aws/apigateway/openapi/substitution-not-performed.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
"200": {
1313
"description": "MyOperation response"
1414
}
15+
},
16+
"x-amazon-apigateway-integration": {
17+
"httpMethod": "POST",
18+
"payloadFormatVersion": "2.0",
19+
"type": "aws_proxy",
20+
"uri": "arn:${Token[AWS.Partition.9]}:apigateway:us-east-1:lambda:path/2015-03-31/functions/${Token[TOKEN.108]}/invocations"
1521
}
1622
}
1723
}

smithy-aws-apigateway-openapi/src/test/resources/software/amazon/smithy/aws/apigateway/openapi/substitution-performed.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
"200": {
1313
"description": "MyOperation response"
1414
}
15+
},
16+
"x-amazon-apigateway-integration": {
17+
"httpMethod": "POST",
18+
"payloadFormatVersion": "2.0",
19+
"type": "aws_proxy",
20+
"uri": "arn:${Token[AWS.Partition.9]}:apigateway:us-east-1:lambda:path/2015-03-31/functions/${Token[TOKEN.108]}/invocations"
1521
}
1622
}
1723
}

0 commit comments

Comments
 (0)