mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
refactor(lambda): tell names from ARNs and read regions through AwsArnUtils (#6881)
The startsWith("arn:") probes in Lambda, Lambda MicroVMs and the API Gateway v2 quick-create target become AwsArnUtils.looksLikeArn. The runtime version ARN and the MicroVM image region read the region with AwsArnUtils.regionOrDefault instead of a split. LambdaTagController keeps its split, marked: Lambda reads the fourth field of any tag target, ARN or not, which IamRestRouteEnforcementIntegrationTest pins.
Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
1 parent
9cea537cfa
commit
63aa7710d0
8 files changed
+11
-23
No files matched your search
+1
-1
@@ -142,7 +142,7 @@ public class ApiGatewayV2Service {
|
||||
Object targetValue = request.get("target");
|
||||
String target = targetValue != null ? String.valueOf(targetValue) : null;
|
||||
if ("HTTP".equals(protocolType) && target != null && !target.isBlank()) {
|
||||
boolean isLambdaTarget = target.startsWith("arn:");
|
||||
boolean isLambdaTarget = AwsArnUtils.looksLikeArn(target);
|
||||
Integration integration = createIntegration(region, apiId, Map.of(
|
||||
"integrationType", isLambdaTarget ? "AWS_PROXY" : "HTTP_PROXY",
|
||||
"integrationUri", target,
|
||||
|
||||
@@ -70,7 +70,7 @@ public final class LambdaArnUtils {
|
||||
*/
|
||||
public static String functionArn(String reference, String partition, String region, String defaultAccount) {
|
||||
ResolvedFunctionRef ref = resolve(reference);
|
||||
if (reference.startsWith("arn:")) {
|
||||
if (AwsArnUtils.looksLikeArn(reference)) {
|
||||
return reference;
|
||||
}
|
||||
String resource = ref.qualifier() == null
|
||||
@@ -106,7 +106,7 @@ public final class LambdaArnUtils {
|
||||
"Member must have length less than or equal to " + MAX_TOTAL_LENGTH);
|
||||
}
|
||||
|
||||
if (input.startsWith("arn:")) {
|
||||
if (AwsArnUtils.looksLikeArn(input)) {
|
||||
return parseFullArn(input);
|
||||
}
|
||||
if (input.contains(":function:")) {
|
||||
|
||||
@@ -905,11 +905,7 @@ public class LambdaController {
|
||||
}
|
||||
|
||||
private String runtimeVersionArn(LambdaFunction fn) {
|
||||
String region = regionResolver.getDefaultRegion();
|
||||
String[] arnParts = fn.getFunctionArn() != null ? fn.getFunctionArn().split(":") : new String[0];
|
||||
if (arnParts.length > 3 && !arnParts[3].isBlank()) {
|
||||
region = arnParts[3];
|
||||
}
|
||||
String region = AwsArnUtils.regionOrDefault(fn.getFunctionArn(), regionResolver.getDefaultRegion());
|
||||
return AwsArnUtils.Arn.of("lambda", region, "", "runtime:" + runtimeVersionId(fn.getRuntime())).toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -661,7 +661,7 @@ public class LambdaService implements ResourceProvider {
|
||||
if (effective == null) {
|
||||
return getFunction(region, functionName);
|
||||
}
|
||||
if (functionName.startsWith("arn:")) {
|
||||
if (AwsArnUtils.looksLikeArn(functionName)) {
|
||||
AwsArnUtils.Arn arn = AwsArnUtils.parse(functionName);
|
||||
return targetResolver.resolveReadTargetForAccount(arn.accountId(), region, ref.name(), effective);
|
||||
}
|
||||
@@ -3742,7 +3742,7 @@ public class LambdaService implements ResourceProvider {
|
||||
if (principal == null) {
|
||||
return null;
|
||||
}
|
||||
if (principal.startsWith("arn:")) {
|
||||
if (AwsArnUtils.looksLikeArn(principal)) {
|
||||
return Map.of("AWS", principal);
|
||||
}
|
||||
if (ACCOUNT_ID_PATTERN.matcher(principal).matches()) {
|
||||
@@ -3966,7 +3966,7 @@ public class LambdaService implements ResourceProvider {
|
||||
* than the mapping's is reported as missing, as AWS does.
|
||||
*/
|
||||
private EventSourceMapping taggedEventSourceMapping(String resourceArn) {
|
||||
if (resourceArn == null || !resourceArn.startsWith("arn:")) {
|
||||
if (!AwsArnUtils.looksLikeArn(resourceArn)) {
|
||||
return null;
|
||||
}
|
||||
AwsArnUtils.Arn arn;
|
||||
@@ -3996,7 +3996,7 @@ public class LambdaService implements ResourceProvider {
|
||||
if (functionArn == null || functionArn.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValueException", "Resource ARN is required", 400);
|
||||
}
|
||||
if (!functionArn.startsWith("arn:")) {
|
||||
if (!AwsArnUtils.looksLikeArn(functionArn)) {
|
||||
throw new AwsException("InvalidParameterValueException",
|
||||
"Resource ARN must be a full Lambda function ARN: " + functionArn, 400);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class LambdaTagController {
|
||||
* the ARN's resource type. The region comes from the ARN itself.
|
||||
*/
|
||||
private static String arnRegion(String arn) {
|
||||
String[] parts = arn.split(":");
|
||||
String[] parts = arn.split(":"); // partition-literal: Lambda reads the fourth field of any tag target, ARN or not
|
||||
return parts.length > 3 ? parts[3] : "";
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -464,8 +464,7 @@ public class LambdaMicrovmsController {
|
||||
* cannot name a different region than the resource it describes.
|
||||
*/
|
||||
private static String regionOf(String arn) {
|
||||
String[] parts = arn.split(":", 5);
|
||||
return parts.length > 3 ? parts[3] : "";
|
||||
return AwsArnUtils.regionOrDefault(arn, "");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -201,7 +201,7 @@ public class LambdaMicrovmsService {
|
||||
* ids/names through — CloudFormation physical ids stay name-based.
|
||||
*/
|
||||
private static String unwrap(String identifier) {
|
||||
if (identifier != null && identifier.startsWith("arn:")) {
|
||||
if (AwsArnUtils.looksLikeArn(identifier)) {
|
||||
return identifier.substring(identifier.lastIndexOf(':') + 1);
|
||||
}
|
||||
return identifier;
|
||||
|
||||
Reference in new issue
Block a user