chore: improve canonicalHostedZone handling

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
This commit is contained in:
ivan katliarchuk 2025-01-24 18:38:31 +00:00
parent 290f8c848d
commit 55e640bd43
No known key found for this signature in database
GPG Key ID: 601CDBBBB76E47BE
2 changed files with 12 additions and 2 deletions

View File

@ -1161,8 +1161,10 @@ func isAWSAlias(ep *endpoint.Endpoint) string {
// canonicalHostedZone returns the matching canonical zone for a given hostname.
func canonicalHostedZone(hostname string) string {
for suffix, zone := range canonicalHostedZones {
if strings.HasSuffix(hostname, suffix) {
parts := strings.Split(hostname, ".")
for i := 0; i < len(parts); i++ {
suffix := strings.Join(parts[i:], ".")
if zone, exists := canonicalHostedZones[suffix]; exists {
return zone
}
}

View File

@ -1882,6 +1882,14 @@ func TestAWSCanonicalHostedZone(t *testing.T) {
assert.Equal(t, "", zone, "no canonical zone should be returned for a non-aws hostname")
}
func BenchmarkTestAWSCanonicalHostedZone(b *testing.B) {
for i := 0; i < b.N; i++ {
for suffix, _ := range canonicalHostedZones {
_ = canonicalHostedZone(fmt.Sprintf("foo.%s", suffix))
}
}
}
func TestAWSSuitableZones(t *testing.T) {
zones := map[string]*profiledZone{
// Public domain