mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(cloudformation): reject non-integer target group ports and health check counts (#4970)
* fix(cloudformation): reject non-integer target group ports and health check counts ElbV2CfnProvisioner turned a non-integer Port, HealthCheckIntervalSeconds, HealthCheckTimeoutSeconds, HealthyThresholdCount or UnhealthyThresholdCount into an unset value and created the target group anyway. The registry schema types all five as integers and CloudFormation fails such a resource, so they now fail with the same ValidationError the listener's Port and the rule's Priority already raise. An absent value still reaches the service unset. * fix(cloudformation): reject a literal blank target group integer, keep AWS::NoValue unset Review on #4970: optionalInt treated a present blank value as absent, so HealthCheckIntervalSeconds: "" still created the target group with the service default, while CloudFormation's schema type check rejects a blank string for an integer property. A literal blank in the template now fails with the same ValidationError. A blank that an intrinsic resolves to stays unset, because the engine resolves AWS::NoValue to blank and Fn::If [cond, value, AWS::NoValue] is how templates drop the property. The javadoc now says exactly that, including the one case still lenient (a Ref to a parameter whose value is blank), and optionalInt parses directly instead of passing parseInt a fallback it could never use. Both integer checks share one error so the message cannot drift.
This commit is contained in:
1 parent
be2998f2a2
commit
a95f4cee3d
2 files changed
+80
-12
No files matched your search
+23
-12
@@ -163,17 +163,17 @@ public class ElbV2CfnProvisioner implements CfnResourceProvisioner {
|
||||
ctx, r.getLogicalId());
|
||||
String protocol = ctx.resolveOptional(props, "Protocol");
|
||||
String protocolVersion = ctx.resolveOptional(props, "ProtocolVersion");
|
||||
Integer port = parseIntOrNull(ctx.resolveOptional(props, "Port"));
|
||||
Integer port = optionalInt(props, ctx, "Port");
|
||||
String vpcId = ctx.resolveOptional(props, "VpcId");
|
||||
String targetType = ctx.resolveOptional(props, "TargetType");
|
||||
String hcProtocol = ctx.resolveOptional(props, "HealthCheckProtocol");
|
||||
String hcPort = ctx.resolveOptional(props, "HealthCheckPort");
|
||||
Boolean hcEnabled = parseBooleanOrNull(ctx.resolveOptional(props, "HealthCheckEnabled"));
|
||||
String hcPath = ctx.resolveOptional(props, "HealthCheckPath");
|
||||
Integer hcInterval = parseIntOrNull(ctx.resolveOptional(props, "HealthCheckIntervalSeconds"));
|
||||
Integer hcTimeout = parseIntOrNull(ctx.resolveOptional(props, "HealthCheckTimeoutSeconds"));
|
||||
Integer healthyThreshold = parseIntOrNull(ctx.resolveOptional(props, "HealthyThresholdCount"));
|
||||
Integer unhealthyThreshold = parseIntOrNull(ctx.resolveOptional(props, "UnhealthyThresholdCount"));
|
||||
Integer hcInterval = optionalInt(props, ctx, "HealthCheckIntervalSeconds");
|
||||
Integer hcTimeout = optionalInt(props, ctx, "HealthCheckTimeoutSeconds");
|
||||
Integer healthyThreshold = optionalInt(props, ctx, "HealthyThresholdCount");
|
||||
Integer unhealthyThreshold = optionalInt(props, ctx, "UnhealthyThresholdCount");
|
||||
String matcher = parseMatcher(props, ctx);
|
||||
String ipAddressType = ctx.resolveOptional(props, "IpAddressType");
|
||||
Map<String, String> tags = ctx.resolveTags(props, "Tags");
|
||||
@@ -471,23 +471,34 @@ public class ElbV2CfnProvisioner implements CfnResourceProvisioner {
|
||||
try {
|
||||
return Integer.parseInt(value.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
throw new AwsException("ValidationError", "Value of property " + property + " must be an integer.", 400);
|
||||
throw notAnInteger(property);
|
||||
}
|
||||
}
|
||||
|
||||
/** The switch treated an unparsable optional integer as unset; kept so a stray value does not fail a stack. */
|
||||
private static Integer parseIntOrNull(String value) {
|
||||
if (value == null || value.isBlank()) {
|
||||
/**
|
||||
* An omitted property stays unset for the service to default, and so does one an intrinsic resolves
|
||||
* to nothing: the engine resolves {@code AWS::NoValue} to blank, which is how the common
|
||||
* {@code Fn::If [cond, value, AWS::NoValue]} drops a property. A value written into the template
|
||||
* has to be an integer, a literal blank included, as CloudFormation's schema type check requires.
|
||||
* A {@code Ref} to a parameter whose value is blank cannot be told apart from {@code AWS::NoValue}
|
||||
* here, so it stays unset too.
|
||||
*/
|
||||
private static Integer optionalInt(JsonNode props, ProvisionContext ctx, String property) {
|
||||
String value = ctx.resolveOptional(props, property);
|
||||
if (value == null || (value.isBlank() && !props.get(property).isTextual())) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Integer.valueOf(value.trim());
|
||||
return Integer.parseInt(value.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
LOG.debugv("Ignoring non-integer value {0}", value);
|
||||
return null;
|
||||
throw notAnInteger(property);
|
||||
}
|
||||
}
|
||||
|
||||
private static AwsException notAnInteger(String property) {
|
||||
return new AwsException("ValidationError", "Value of property " + property + " must be an integer.", 400);
|
||||
}
|
||||
|
||||
private static Boolean parseBooleanOrNull(String value) {
|
||||
return value == null || value.isBlank() ? null : Boolean.valueOf(value);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user