mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
refactor(ecs): tell names from ARNs through AwsArnUtils.looksLikeArn (#6879)
The eleven startsWith("arn:") probes in EcsService, EcsContainerManager and EcsCfnProvisioner become AwsArnUtils.looksLikeArn, which is the same check, and the null guards it already makes are dropped.
Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
1 parent
043664471b
commit
9cea537cfa
4 files changed
+11
-14
No files matched your search
+1
-1
@@ -389,7 +389,7 @@ public class EcsCfnProvisioner implements CfnResourceProvisioner {
|
||||
return "default";
|
||||
}
|
||||
int slash = clusterRef.lastIndexOf('/');
|
||||
return clusterRef.startsWith("arn:") && slash >= 0 ? clusterRef.substring(slash + 1) : clusterRef;
|
||||
return AwsArnUtils.looksLikeArn(clusterRef) && slash >= 0 ? clusterRef.substring(slash + 1) : clusterRef;
|
||||
}
|
||||
|
||||
/** The cluster segment of {@code service/<cluster>/<name>}; the legacy {@code service/<name>} form is the default. */
|
||||
|
||||
@@ -709,7 +709,7 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
if (cluster != null) {
|
||||
result.add(cluster);
|
||||
} else {
|
||||
failures.add(Failure.missing(id != null && id.startsWith("arn:")
|
||||
failures.add(Failure.missing(AwsArnUtils.looksLikeArn(id)
|
||||
? id : regionResolver.buildArn("ecs", region, "cluster/" + id)));
|
||||
}
|
||||
}
|
||||
@@ -1407,7 +1407,7 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
if (ref == null) {
|
||||
return false;
|
||||
}
|
||||
String tail = ref.startsWith("arn:") ? ref.substring(ref.lastIndexOf('/') + 1) : ref;
|
||||
String tail = AwsArnUtils.looksLikeArn(ref) ? ref.substring(ref.lastIndexOf('/') + 1) : ref;
|
||||
int colon = tail.lastIndexOf(':');
|
||||
if (colon < 0) {
|
||||
return false;
|
||||
@@ -2371,7 +2371,7 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
if (task != null) {
|
||||
result.add(task);
|
||||
} else {
|
||||
failures.add(Failure.missing(ref != null && ref.startsWith("arn:")
|
||||
failures.add(Failure.missing(AwsArnUtils.looksLikeArn(ref)
|
||||
? ref
|
||||
: regionResolver.buildArn("ecs", region,
|
||||
"task/" + cluster.getClusterName() + "/" + ref)));
|
||||
@@ -3063,7 +3063,7 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
|
||||
/** Echoes an ARN the caller supplied, otherwise builds the ARN the service would have had. */
|
||||
private String missingServiceArn(EcsCluster cluster, String serviceRef, String region) {
|
||||
if (serviceRef != null && serviceRef.startsWith("arn:")) {
|
||||
if (AwsArnUtils.looksLikeArn(serviceRef)) {
|
||||
return serviceRef;
|
||||
}
|
||||
return regionResolver.buildArn("ecs", region,
|
||||
@@ -3593,7 +3593,7 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
if (instance != null) {
|
||||
result.add(instance);
|
||||
} else {
|
||||
failures.add(Failure.missing(ref.startsWith("arn:") ? ref
|
||||
failures.add(Failure.missing(AwsArnUtils.looksLikeArn(ref) ? ref
|
||||
: containerInstanceArnFor(cluster, ref, region)));
|
||||
}
|
||||
}
|
||||
@@ -3666,7 +3666,7 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
for (String ref : instanceRefs) {
|
||||
ContainerInstance instance = resolveContainerInstance(cluster.getClusterArn(), ref);
|
||||
if (instance == null) {
|
||||
failures.add(Failure.missing(ref.startsWith("arn:") ? ref
|
||||
failures.add(Failure.missing(AwsArnUtils.looksLikeArn(ref) ? ref
|
||||
: containerInstanceArnFor(cluster, ref, region)));
|
||||
continue;
|
||||
}
|
||||
@@ -3791,7 +3791,7 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
.findFirst().orElse(null));
|
||||
};
|
||||
if (cp == null) {
|
||||
failures.add(Failure.missing(ref.startsWith("arn:") ? ref
|
||||
failures.add(Failure.missing(AwsArnUtils.looksLikeArn(ref) ? ref
|
||||
: regionResolver.buildArn("ecs", region, "capacity-provider/" + ref)));
|
||||
continue;
|
||||
}
|
||||
@@ -4073,7 +4073,7 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
if (match != null) {
|
||||
found.add(match);
|
||||
} else {
|
||||
failures.add(Failure.missing(ref.startsWith("arn:") ? ref
|
||||
failures.add(Failure.missing(AwsArnUtils.looksLikeArn(ref) ? ref
|
||||
: regionResolver.buildArn("ecs", region, "task-set/"
|
||||
+ cluster.getClusterName() + "/" + svc.getServiceName() + "/" + ref)));
|
||||
}
|
||||
@@ -5230,7 +5230,7 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
*/
|
||||
private String resolvedTaskDefinitionArn(EcsServiceModel svc, String region) {
|
||||
String ref = svc.getTaskDefinition();
|
||||
if (ref == null || ref.startsWith("arn:")) {
|
||||
if (ref == null || AwsArnUtils.looksLikeArn(ref)) {
|
||||
return ref;
|
||||
}
|
||||
try {
|
||||
|
||||
+1
-1
@@ -2124,7 +2124,7 @@ public class EcsContainerManager {
|
||||
|
||||
/** The region embedded in an ARN {@code valueFrom} (4th segment), or {@code taskRegion} for a bare name. */
|
||||
private String arnRegion(String valueFrom, String taskRegion) {
|
||||
if (valueFrom != null && valueFrom.startsWith("arn:")) {
|
||||
if (AwsArnUtils.looksLikeArn(valueFrom)) {
|
||||
String[] parts = valueFrom.split(":", 5);
|
||||
if (parts.length >= 4 && !parts[3].isBlank()) {
|
||||
return parts[3];
|
||||
|
||||
Reference in new issue
Block a user