Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

refactor(cloudformation): check ARNs through AwsArnUtils (#6486)

Hector Ventura31b48c30be52
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java
index 00e85aa583..0868281dcc 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java
@@ -4349,7 +4349,7 @@ public class CloudFormationService implements ResourceProvider {
}
private Stack resolveDeletedStack(String stackNameOrArn, String region, String accountId) {
- if (stackNameOrArn != null && stackNameOrArn.startsWith("arn:")) {
+ if (AwsArnUtils.isArn(stackNameOrArn)) {
DeletedStackEntry deleted = deletedStacks.get(stackNameOrArn);
if (deleted != null) {
if (deleted.isExpired(now())) {
@@ -4455,7 +4455,7 @@ public class CloudFormationService implements ResourceProvider {
String region, String accountId) {
ChangeSet changeSet = stack.getChangeSets().get(
resolveChangeSetName(changeSetNameOrArn, region, accountId));
- if (changeSet == null || (changeSetNameOrArn != null && changeSetNameOrArn.startsWith("arn:")
+ if (changeSet == null || (AwsArnUtils.isArn(changeSetNameOrArn)
&& !changeSetNameOrArn.equals(changeSet.getChangeSetId()))) {
return null;
}
@@ -4648,7 +4648,7 @@ public class CloudFormationService implements ResourceProvider {
}
// If input looks like an ARN, extract the stack name and retry
- if (stackNameOrArn != null && stackNameOrArn.startsWith("arn:")) {
+ if (AwsArnUtils.isArn(stackNameOrArn)) {
try {
AwsArnUtils.Arn arn = AwsArnUtils.parse(stackNameOrArn);
if (!accountId.equals(arn.accountId()) || !region.equals(arn.region())) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/BatchCfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/BatchCfnProvisioner.java
index dfdc213ac0..8ddd759b4c 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/BatchCfnProvisioner.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/BatchCfnProvisioner.java
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.batch.BatchService;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
@@ -472,7 +473,7 @@ public class BatchCfnProvisioner implements CfnResourceProvisioner {
return recorded;
}
String priorId = ctx.priorPhysicalId();
- if (priorId == null || !priorId.startsWith("arn:")) {
+ if (!AwsArnUtils.isArn(priorId)) {
return null;
}
int slash = priorId.lastIndexOf('/');
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/BedrockAgentCoreCfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/BedrockAgentCoreCfnProvisioner.java
index fcb1c013e9..6dc98aae7c 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/BedrockAgentCoreCfnProvisioner.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/BedrockAgentCoreCfnProvisioner.java
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.BedrockAgentCoreControlService;
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.BedrockAgentCoreControlService.EndpointLocation;
@@ -355,7 +356,7 @@ public class BedrockAgentCoreCfnProvisioner implements CfnResourceProvisioner {
/** The memory a prior physical id names, or null when it names none (gone, or a dispatcher stub). */
private Memory findMemory(String arn, String region) {
- if (!arn.startsWith("arn:")) {
+ if (!AwsArnUtils.isArn(arn)) {
return null;
}
try {
@@ -398,7 +399,7 @@ public class BedrockAgentCoreCfnProvisioner implements CfnResourceProvisioner {
physicalId));
case MEMORY -> {
// A dispatcher stub from before this provisioner existed is not an ARN and names no memory.
- if (!physicalId.startsWith("arn:")) {
+ if (!AwsArnUtils.isArn(physicalId)) {
return;
}
CfnDeletes.safeDelete("AgentCore memory", physicalId,
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/IamPolicyCfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/IamPolicyCfnProvisioner.java
index 647621bcd1..6786aba578 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/IamPolicyCfnProvisioner.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/IamPolicyCfnProvisioner.java
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation.provisioners;
import com.fasterxml.jackson.databind.JsonNode;
+import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.cloudformation.CloudFormationTemplateEngine;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
@@ -343,8 +344,7 @@ public class IamPolicyCfnProvisioner implements CfnResourceProvisioner {
}
private boolean isIamManagedPolicyArn(String physicalId) {
- return physicalId != null
- && physicalId.startsWith("arn:")
+ return AwsArnUtils.isArn(physicalId)
&& physicalId.contains(":iam::")
&& physicalId.contains(":policy/");
}
diff --git a/tools/partition/baseline.tsv b/tools/partition/baseline.tsv
index eee9f42596..d6e9a589b0 100644
--- a/tools/partition/baseline.tsv
+++ b/tools/partition/baseline.tsv
@@ -19,12 +19,9 @@ arn-probe src/main/java/io/github/hectorvent/floci/services/appsync/graphql/reso
arn-probe src/main/java/io/github/hectorvent/floci/services/batch/BatchService.java 4
arn-probe src/main/java/io/github/hectorvent/floci/services/bedrock/BedrockService.java 3
arn-probe src/main/java/io/github/hectorvent/floci/services/budgets/BudgetsService.java 1
-arn-probe src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java 7
-arn-probe src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/BatchCfnProvisioner.java 1
-arn-probe src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/BedrockAgentCoreCfnProvisioner.java 2
+arn-probe src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java 4
arn-probe src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/Ec2InstanceCfnProvisioner.java 1
arn-probe src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/EcsCfnProvisioner.java 1
-arn-probe src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/IamPolicyCfnProvisioner.java 1
arn-probe src/main/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontService.java 1
arn-probe src/main/java/io/github/hectorvent/floci/services/cloudtrail/CloudTrailService.java 1
arn-probe src/main/java/io/github/hectorvent/floci/services/cloudwatch/logs/CloudWatchLogsCrossAccountService.java 1