refactor(24): consolidate duplicate sanitizeAwsError into single source

Plan 24-04's isolated worktree didn't have plan 24-03's
route53-record-validation.ts available (parallel wave, no direct
dependency), so it carried a local copy of the identical AWS error
redaction logic — flagged in its own SUMMARY for consolidation once
24-03 merged. Both plans are now merged; importing the shared
implementation instead of keeping two copies in sync.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
lorentz 2026-08-05 20:27:01 -04:00
parent d00c47ecb1
commit e727ddca77

View file

@ -19,6 +19,7 @@
import { ListHostedZonesCommand } from '@aws-sdk/client-route-53';
import { isRoute53Configured, getRoute53Client } from '@/lib/services/route53-factory';
import { checkAllZoneDelegations } from '@/lib/services/route53-dns-delegation';
import { sanitizeAwsError } from '@/lib/services/route53-record-validation';
export type HealthStatus =
| 'ok' // configured, auth succeeded
@ -201,29 +202,6 @@ async function checkDattoRmm(): Promise<IntegrationHealth> {
}
}
/**
* Redact an AWS SDK error down to a message safe to surface in the health
* API response and (eventually) route53_audit_log.error_message.
*
* NOTE: this duplicates the `sanitizeAwsError` spec'd for
* `lib/services/route53-record-validation.ts` in plan 24-03 (T-24-03). That
* file did not exist in this plan's isolated worktree at execution time
* (24-03 runs in a sibling parallel worktree and depends_on for this plan
* only lists 24-01) see this plan's SUMMARY "Deviations" section. This
* local copy uses the identical redaction rules so behavior is consistent
* regardless of which implementation ships; if 24-03 lands first in a
* future merge, this local copy should be replaced with an import from
* `@/lib/services/route53-record-validation` for a single source of truth.
*/
function sanitizeAwsError(err: unknown): string {
const message = err instanceof Error ? err.message : String(err);
return message
.replace(/AKIA[0-9A-Z]{16}/g, '[redacted-key-id]')
.replace(/arn:aws:[^\s"']+/g, '[redacted-arn]')
.replace(/\b[0-9]{12}\b/g, '[redacted-account-id]')
.slice(0, 500);
}
const AWS_AUTH_ERROR_NAMES = new Set([
'InvalidClientTokenId',
'SignatureDoesNotMatch',