Skip to content

Commit 67d80a8

Browse files
committed
fix(operator): match typed EC2 error code for duplicate SG rule
Round-5 review F1: ensure_sg_ingress classified the "rule already exists" case by substring-matching the Debug-rendered error string, which breaks if the SDK changes error formatting. Match the typed AWS error code InvalidPermission.Duplicate via ProvideErrorMetadata::code() instead. (F2 — CI green — the operator job now passes on the prior commit.) Verified: build, clippy --all-targets -D warnings, cargo test (12 passed).
1 parent 6f92a2e commit 67d80a8

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

operator/src/ingress.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ async fn ensure_sg_ingress(
329329
security_groups: &[String],
330330
port: u16,
331331
) -> Result<()> {
332+
use aws_sdk_ec2::error::ProvideErrorMetadata;
332333
use aws_sdk_ec2::types::{IpPermission, UserIdGroupPair};
333334
for sg in security_groups {
334335
// Self-referencing rule: VPC Link ENIs live in this SG, so allowing the
@@ -348,14 +349,14 @@ async fn ensure_sg_ingress(
348349
.await
349350
{
350351
Ok(_) => eprintln!(" ✓ SG {sg}: allowed self :{port} (VPC Link → task)"),
352+
// EC2 returns InvalidPermission.Duplicate when the rule already exists.
353+
// Match the typed error code, not the Debug-rendered message text.
354+
Err(e) if e.code() == Some("InvalidPermission.Duplicate") => {
355+
eprintln!(" ✓ SG {sg}: inbound :{port} rule already present");
356+
}
351357
Err(e) => {
352-
let msg = format!("{e:?}");
353-
if msg.contains("Duplicate") || msg.contains("already exists") {
354-
eprintln!(" ✓ SG {sg}: inbound :{port} rule already present");
355-
} else {
356-
return Err(anyhow::anyhow!(e))
357-
.with_context(|| format!("failed to authorize ingress on {sg}"));
358-
}
358+
return Err(anyhow::anyhow!(e))
359+
.with_context(|| format!("failed to authorize ingress on {sg}"));
359360
}
360361
}
361362
}

0 commit comments

Comments
 (0)