mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(lambda): reject invalid configuration numbers before mutation (#4726)
* fix(lambda): reject invalid configuration numbers before mutation * fix(lambda): validate configuration ARN types and memory limit
This commit is contained in:
1 parent
45b00779b7
commit
894f20bb81
4 files changed
+170
-5
No files matched your search
@@ -790,7 +790,10 @@ public class LambdaService implements ResourceProvider {
|
||||
if (request.containsKey("Runtime")) {
|
||||
validateEnum(request.get("Runtime"), "runtime", RUNTIME_VALUES);
|
||||
}
|
||||
validatePattern(request.get("KMSKeyArn"), "kmsKeyArn", KMS_KEY_ARN_PATTERN);
|
||||
String kmsKeyArn = validatedOptionalString(request.get("KMSKeyArn"), "KMSKeyArn");
|
||||
String deadLetterTargetArn = deadLetterConfig == null ? null
|
||||
: validatedOptionalString(deadLetterConfig.get("TargetArn"), "DeadLetterConfig.TargetArn");
|
||||
validatePattern(kmsKeyArn, "kmsKeyArn", KMS_KEY_ARN_PATTERN);
|
||||
if (request.containsKey("SnapStart")) {
|
||||
validateSnapStart(snapStart);
|
||||
}
|
||||
@@ -803,6 +806,10 @@ public class LambdaService implements ResourceProvider {
|
||||
if (request.containsKey("Handler")) {
|
||||
validateHandler((String) request.get("Handler"));
|
||||
}
|
||||
int memorySize = request.containsKey("MemorySize")
|
||||
? validatedConfigurationInteger(request.get("MemorySize"), "MemorySize", 128, 10240) : 0;
|
||||
int timeout = request.containsKey("Timeout")
|
||||
? validatedConfigurationInteger(request.get("Timeout"), "Timeout", 1, 900) : 0;
|
||||
|
||||
Map<String, Object> requestedVpcConfig = fn.getVpcConfig();
|
||||
if (requestedVpcConfigUpdate != null) {
|
||||
@@ -823,7 +830,7 @@ public class LambdaService implements ResourceProvider {
|
||||
fn.setHandler((String) request.get("Handler"));
|
||||
}
|
||||
if (request.containsKey("MemorySize")) {
|
||||
fn.setMemorySize(((Number) request.get("MemorySize")).intValue());
|
||||
fn.setMemorySize(memorySize);
|
||||
}
|
||||
if (request.containsKey("Role")) {
|
||||
fn.setRole((String) request.get("Role"));
|
||||
@@ -832,7 +839,7 @@ public class LambdaService implements ResourceProvider {
|
||||
fn.setRuntime((String) request.get("Runtime"));
|
||||
}
|
||||
if (request.containsKey("Timeout")) {
|
||||
fn.setTimeout(((Number) request.get("Timeout")).intValue());
|
||||
fn.setTimeout(timeout);
|
||||
}
|
||||
if (request.containsKey("Environment")) {
|
||||
if (environment != null && environment.containsKey("Variables")) {
|
||||
@@ -870,7 +877,7 @@ public class LambdaService implements ResourceProvider {
|
||||
|
||||
if (request.containsKey("DeadLetterConfig")) {
|
||||
if (deadLetterConfig != null) {
|
||||
fn.setDeadLetterTargetArn((String) deadLetterConfig.get("TargetArn"));
|
||||
fn.setDeadLetterTargetArn(deadLetterTargetArn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -879,7 +886,7 @@ public class LambdaService implements ResourceProvider {
|
||||
}
|
||||
|
||||
if (request.containsKey("KMSKeyArn")) {
|
||||
fn.setKmsKeyArn((String) request.get("KMSKeyArn"));
|
||||
fn.setKmsKeyArn(kmsKeyArn);
|
||||
}
|
||||
|
||||
if (request.containsKey("VpcConfig")) {
|
||||
@@ -931,6 +938,22 @@ public class LambdaService implements ResourceProvider {
|
||||
return fn;
|
||||
}
|
||||
|
||||
private static int validatedConfigurationInteger(Object value, String field, int minimum, int maximum) {
|
||||
if (!(value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long)
|
||||
|| ((Number) value).longValue() < minimum || ((Number) value).longValue() > maximum) {
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
field + " must be an integer between " + minimum + " and " + maximum, 400);
|
||||
}
|
||||
return ((Number) value).intValue();
|
||||
}
|
||||
|
||||
private static String validatedOptionalString(Object value, String field) {
|
||||
if (value != null && !(value instanceof String)) {
|
||||
throw new AwsException("InvalidParameterValueException", field + " must be a string", 400);
|
||||
}
|
||||
return (String) value;
|
||||
}
|
||||
|
||||
/**
|
||||
* DeleteFunction without a Qualifier: removes the function and every version of it.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user