mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(lambda): add missing FunctionConfiguration fields and fix response shape (#546)
This commit is contained in:
1 parent
999ac85ffa
commit
ce60457392
5 files changed
+675
-2
No files matched your search
@@ -26,6 +26,9 @@ import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -502,15 +505,46 @@ public class LambdaController {
|
||||
if (fn.getStateReason() != null) node.put("StateReason", fn.getStateReason());
|
||||
if (fn.getStateReasonCode() != null) node.put("StateReasonCode", fn.getStateReasonCode());
|
||||
node.put("CodeSize", fn.getCodeSizeBytes());
|
||||
node.put("CodeSha256", fn.getCodeSha256() != null ? fn.getCodeSha256() : "");
|
||||
node.put("PackageType", fn.getPackageType());
|
||||
if (fn.getImageUri() != null) node.put("ImageUri", fn.getImageUri());
|
||||
node.put("LastModified", String.valueOf(fn.getLastModified()));
|
||||
node.put("LastModified", DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
|
||||
.format(Instant.ofEpochMilli(fn.getLastModified()).atOffset(ZoneOffset.UTC)));
|
||||
node.put("RevisionId", fn.getRevisionId());
|
||||
node.put("Version", fn.getVersion());
|
||||
node.put("LastUpdateStatus", "Successful");
|
||||
|
||||
// Architectures — always present; default x86_64
|
||||
ArrayNode archNode = node.putArray("Architectures");
|
||||
List<String> archs = fn.getArchitectures();
|
||||
(archs != null && !archs.isEmpty() ? archs : List.of("x86_64")).forEach(archNode::add);
|
||||
|
||||
// EphemeralStorage — always present; AWS default 512 MB
|
||||
node.putObject("EphemeralStorage").put("Size", fn.getEphemeralStorageSize());
|
||||
|
||||
// TracingConfig — always present
|
||||
node.putObject("TracingConfig")
|
||||
.put("Mode", fn.getTracingMode() != null ? fn.getTracingMode() : "PassThrough");
|
||||
|
||||
// DeadLetterConfig — only when set
|
||||
if (fn.getDeadLetterTargetArn() != null) {
|
||||
node.putObject("DeadLetterConfig").put("TargetArn", fn.getDeadLetterTargetArn());
|
||||
}
|
||||
|
||||
// Layers — only when non-empty
|
||||
if (fn.getLayers() != null && !fn.getLayers().isEmpty()) {
|
||||
ArrayNode layersNode = node.putArray("Layers");
|
||||
fn.getLayers().forEach(arn -> layersNode.addObject().put("Arn", arn));
|
||||
}
|
||||
|
||||
// KMSKeyArn — only when set
|
||||
if (fn.getKmsKeyArn() != null) {
|
||||
node.put("KMSKeyArn", fn.getKmsKeyArn());
|
||||
}
|
||||
|
||||
// Environment — always present (SDK expects it even when empty)
|
||||
ObjectNode envNode = node.putObject("Environment");
|
||||
if (fn.getEnvironment() != null && !fn.getEnvironment().isEmpty()) {
|
||||
ObjectNode envNode = node.putObject("Environment");
|
||||
ObjectNode vars = envNode.putObject("Variables");
|
||||
fn.getEnvironment().forEach(vars::put);
|
||||
}
|
||||
|
||||
@@ -232,6 +232,48 @@ public class LambdaService {
|
||||
Map<String, String> tags = (Map<String, String>) request.get("Tags");
|
||||
if (tags != null) fn.setTags(tags);
|
||||
|
||||
// Architectures
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> architectures = request.get("Architectures") instanceof List
|
||||
? (List<String>) request.get("Architectures") : null;
|
||||
if (architectures != null && !architectures.isEmpty()) {
|
||||
fn.setArchitectures(new ArrayList<>(architectures));
|
||||
}
|
||||
|
||||
// EphemeralStorage
|
||||
if (request.get("EphemeralStorage") instanceof Map<?, ?> es) {
|
||||
fn.setEphemeralStorageSize(toInt(es.get("Size"), 512));
|
||||
}
|
||||
|
||||
// TracingConfig
|
||||
if (request.get("TracingConfig") instanceof Map<?, ?> tc) {
|
||||
Object mode = tc.get("Mode");
|
||||
fn.setTracingMode(mode != null ? mode.toString() : "PassThrough");
|
||||
}
|
||||
|
||||
// DeadLetterConfig
|
||||
if (request.get("DeadLetterConfig") instanceof Map<?, ?> dlq) {
|
||||
fn.setDeadLetterTargetArn((String) dlq.get("TargetArn"));
|
||||
}
|
||||
|
||||
// Layers
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> layers = request.get("Layers") instanceof List
|
||||
? (List<String>) request.get("Layers") : null;
|
||||
if (layers != null) {
|
||||
fn.setLayers(new ArrayList<>(layers));
|
||||
}
|
||||
|
||||
if (request.containsKey("KMSKeyArn")) {
|
||||
fn.setKmsKeyArn((String) request.get("KMSKeyArn"));
|
||||
}
|
||||
|
||||
if (request.get("VpcConfig") instanceof Map<?, ?>) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> vpc = (Map<String, Object>) request.get("VpcConfig");
|
||||
fn.setVpcConfig(vpc);
|
||||
}
|
||||
|
||||
// Handle code deployment
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> code = (Map<String, Object>) request.get("Code");
|
||||
@@ -361,6 +403,64 @@ public class LambdaService {
|
||||
}
|
||||
}
|
||||
|
||||
// RevisionId optimistic locking
|
||||
if (request.containsKey("RevisionId")) {
|
||||
String incomingRevision = (String) request.get("RevisionId");
|
||||
if (incomingRevision != null && !incomingRevision.equals(fn.getRevisionId())) {
|
||||
throw new AwsException("PreconditionFailedException",
|
||||
"The Revision Id provided does not match the latest Revision Id. "
|
||||
+ "Call the GetFunction or the GetFunctionConfiguration API to retrieve "
|
||||
+ "the latest Revision Id for your resource.", 412);
|
||||
}
|
||||
}
|
||||
|
||||
if (request.containsKey("Architectures")) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> archs = request.get("Architectures") instanceof List
|
||||
? (List<String>) request.get("Architectures") : null;
|
||||
if (archs != null && !archs.isEmpty()) {
|
||||
fn.setArchitectures(new ArrayList<>(archs));
|
||||
}
|
||||
}
|
||||
|
||||
if (request.containsKey("EphemeralStorage")) {
|
||||
if (request.get("EphemeralStorage") instanceof Map<?, ?> es) {
|
||||
fn.setEphemeralStorageSize(toInt(es.get("Size"), 512));
|
||||
}
|
||||
}
|
||||
|
||||
if (request.containsKey("TracingConfig")) {
|
||||
if (request.get("TracingConfig") instanceof Map<?, ?> tc) {
|
||||
Object mode = tc.get("Mode");
|
||||
fn.setTracingMode(mode != null ? mode.toString() : "PassThrough");
|
||||
}
|
||||
}
|
||||
|
||||
if (request.containsKey("DeadLetterConfig")) {
|
||||
if (request.get("DeadLetterConfig") instanceof Map<?, ?> dlq) {
|
||||
fn.setDeadLetterTargetArn((String) dlq.get("TargetArn"));
|
||||
}
|
||||
}
|
||||
|
||||
if (request.containsKey("Layers")) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> layerList = request.get("Layers") instanceof List
|
||||
? (List<String>) request.get("Layers") : null;
|
||||
fn.setLayers(layerList != null ? new ArrayList<>(layerList) : new ArrayList<>());
|
||||
}
|
||||
|
||||
if (request.containsKey("KMSKeyArn")) {
|
||||
fn.setKmsKeyArn((String) request.get("KMSKeyArn"));
|
||||
}
|
||||
|
||||
if (request.containsKey("VpcConfig")) {
|
||||
if (request.get("VpcConfig") instanceof Map<?, ?>) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> vpc = (Map<String, Object>) request.get("VpcConfig");
|
||||
fn.setVpcConfig(vpc);
|
||||
}
|
||||
}
|
||||
|
||||
fn.setLastModified(System.currentTimeMillis());
|
||||
fn.setRevisionId(UUID.randomUUID().toString());
|
||||
|
||||
@@ -927,6 +1027,10 @@ public class LambdaService {
|
||||
zipExtractor.extractTo(zipBytes, codePath);
|
||||
fn.setCodeLocalPath(codePath.toAbsolutePath().normalize().toString());
|
||||
fn.setCodeSizeBytes(zipBytes.length);
|
||||
try {
|
||||
byte[] digest = java.security.MessageDigest.getInstance("SHA-256").digest(zipBytes);
|
||||
fn.setCodeSha256(Base64.getEncoder().encodeToString(digest));
|
||||
} catch (java.security.NoSuchAlgorithmException ignored) {}
|
||||
|
||||
// For file-based runtimes, verify handler file exists (skip Java and .NET which use different handler formats)
|
||||
if (fn.getRuntime() != null && !fn.getRuntime().startsWith("java") && !fn.getRuntime().startsWith("dotnet")) {
|
||||
|
||||
@@ -38,6 +38,14 @@ public class LambdaFunction {
|
||||
private String version = "$LATEST";
|
||||
private LambdaUrlConfig urlConfig;
|
||||
private Integer reservedConcurrentExecutions;
|
||||
private List<String> architectures;
|
||||
private int ephemeralStorageSize = 512;
|
||||
private String tracingMode = "PassThrough";
|
||||
private String deadLetterTargetArn;
|
||||
private List<String> layers = new ArrayList<>();
|
||||
private String kmsKeyArn;
|
||||
private Map<String, Object> vpcConfig;
|
||||
private String codeSha256;
|
||||
|
||||
@JsonIgnore
|
||||
private volatile ContainerState containerState = ContainerState.COLD;
|
||||
@@ -120,6 +128,30 @@ public class LambdaFunction {
|
||||
public Integer getReservedConcurrentExecutions() { return reservedConcurrentExecutions; }
|
||||
public void setReservedConcurrentExecutions(Integer reservedConcurrentExecutions) { this.reservedConcurrentExecutions = reservedConcurrentExecutions; }
|
||||
|
||||
public List<String> getArchitectures() { return architectures; }
|
||||
public void setArchitectures(List<String> architectures) { this.architectures = architectures; }
|
||||
|
||||
public int getEphemeralStorageSize() { return ephemeralStorageSize; }
|
||||
public void setEphemeralStorageSize(int ephemeralStorageSize) { this.ephemeralStorageSize = ephemeralStorageSize; }
|
||||
|
||||
public String getTracingMode() { return tracingMode; }
|
||||
public void setTracingMode(String tracingMode) { this.tracingMode = tracingMode; }
|
||||
|
||||
public String getDeadLetterTargetArn() { return deadLetterTargetArn; }
|
||||
public void setDeadLetterTargetArn(String deadLetterTargetArn) { this.deadLetterTargetArn = deadLetterTargetArn; }
|
||||
|
||||
public List<String> getLayers() { return layers; }
|
||||
public void setLayers(List<String> layers) { this.layers = layers; }
|
||||
|
||||
public String getKmsKeyArn() { return kmsKeyArn; }
|
||||
public void setKmsKeyArn(String kmsKeyArn) { this.kmsKeyArn = kmsKeyArn; }
|
||||
|
||||
public Map<String, Object> getVpcConfig() { return vpcConfig; }
|
||||
public void setVpcConfig(Map<String, Object> vpcConfig) { this.vpcConfig = vpcConfig; }
|
||||
|
||||
public String getCodeSha256() { return codeSha256; }
|
||||
public void setCodeSha256(String codeSha256) { this.codeSha256 = codeSha256; }
|
||||
|
||||
@JsonIgnore
|
||||
public ContainerState getContainerState() { return containerState; }
|
||||
@JsonIgnore
|
||||
|
||||
Reference in new issue
Block a user