@@ -567,18 +567,21 @@ func (p *AWSProvider) records(ctx context.Context, zones map[string]*profiledZon
567
567
}
568
568
569
569
func handleGeoProximityLocationRecord (r * route53types.ResourceRecordSet , ep * endpoint.Endpoint ) {
570
- if r .GeoProximityLocation .AWSRegion != nil {
571
- ep .WithProviderSpecific (providerSpecificGeoProximityLocationAWSRegion , aws . ToString ( r . GeoProximityLocation . AWSRegion ) )
570
+ if region := aws . ToString ( r .GeoProximityLocation .AWSRegion ); region != "" {
571
+ ep .WithProviderSpecific (providerSpecificGeoProximityLocationAWSRegion , region )
572
572
}
573
- if r .GeoProximityLocation .Bias != nil {
574
- ep .WithProviderSpecific (providerSpecificGeoProximityLocationBias , fmt .Sprintf ("%d" , aws .ToInt32 (r .GeoProximityLocation .Bias )))
573
+
574
+ if bias := r .GeoProximityLocation .Bias ; bias != nil {
575
+ ep .WithProviderSpecific (providerSpecificGeoProximityLocationBias , fmt .Sprintf ("%d" , aws .ToInt32 (bias )))
575
576
}
576
- if r .GeoProximityLocation .Coordinates != nil {
577
- coordinates := fmt .Sprintf ("%s,%s" , aws .ToString (r .GeoProximityLocation .Coordinates .Latitude ), aws .ToString (r .GeoProximityLocation .Coordinates .Longitude ))
577
+
578
+ if coords := r .GeoProximityLocation .Coordinates ; coords != nil {
579
+ coordinates := fmt .Sprintf ("%s,%s" , aws .ToString (coords .Latitude ), aws .ToString (coords .Longitude ))
578
580
ep .WithProviderSpecific (providerSpecificGeoProximityLocationCoordinates , coordinates )
579
581
}
580
- if r .GeoProximityLocation .LocalZoneGroup != nil {
581
- ep .WithProviderSpecific (providerSpecificGeoProximityLocationLocalZoneGroup , aws .ToString (r .GeoProximityLocation .LocalZoneGroup ))
582
+
583
+ if localZoneGroup := aws .ToString (r .GeoProximityLocation .LocalZoneGroup ); localZoneGroup != "" {
584
+ ep .WithProviderSpecific (providerSpecificGeoProximityLocationLocalZoneGroup , localZoneGroup )
582
585
}
583
586
}
584
587
@@ -968,7 +971,7 @@ func (p *AWSProvider) newChange(action route53types.ChangeAction, ep *endpoint.E
968
971
change .ResourceRecordSet .GeoLocation = geolocation
969
972
}
970
973
971
- buildChangeForGeoProximityEndpoint (change , ep )
974
+ withChangeForGeoProximityEndpoint (change , ep )
972
975
}
973
976
974
977
if prop , ok := ep .GetProviderSpecificProperty (providerSpecificHealthCheckID ); ok {
@@ -982,37 +985,77 @@ func (p *AWSProvider) newChange(action route53types.ChangeAction, ep *endpoint.E
982
985
return change
983
986
}
984
987
985
- func buildChangeForGeoProximityEndpoint (change * Route53Change , ep * endpoint.Endpoint ) {
988
+ func withChangeForGeoProximityEndpoint (change * Route53Change , ep * endpoint.Endpoint ) {
986
989
geoproximity := & route53types.GeoProximityLocation {}
987
- useGeoproximity := false
990
+ isGeoproximity := false
991
+
992
+ isGeoproximity = withGeoProximityAWSRegion (ep , geoproximity )
993
+ isGeoproximity = isGeoproximity || withGeoProximityCoordinates (ep , geoproximity )
994
+ isGeoproximity = isGeoproximity || withGeoProximityLocalZoneGroup (ep , geoproximity )
995
+ withGeoProximityBias (ep , geoproximity )
996
+
997
+ if isGeoproximity {
998
+ change .ResourceRecordSet .GeoProximityLocation = geoproximity
999
+ }
1000
+ }
1001
+
1002
+ func withGeoProximityAWSRegion (ep * endpoint.Endpoint , geoproximity * route53types.GeoProximityLocation ) bool {
988
1003
if prop , ok := ep .GetProviderSpecificProperty (providerSpecificGeoProximityLocationAWSRegion ); ok {
989
1004
geoproximity .AWSRegion = aws .String (prop )
990
- useGeoproximity = true
1005
+ return true
991
1006
}
992
- if prop , ok := ep .GetProviderSpecificProperty (providerSpecificGeoProximityLocationBias ); ok {
993
- bias , _ := strconv .ParseInt (prop , 10 , 32 )
994
- geoproximity .Bias = aws .Int32 (int32 (bias ))
1007
+ return false
1008
+ }
1009
+
1010
+ // validateCoordinates checks if the given latitude and longitude are valid.
1011
+ func validateCoordinates (lat , long string ) error {
1012
+ latitude , err := strconv .ParseFloat (lat , 64 )
1013
+ if err != nil || latitude < - 90 || latitude > 90 {
1014
+ return errors .New ("invalid latitude: must be a number between -90 and 90" )
1015
+ }
1016
+
1017
+ longitude , err := strconv .ParseFloat (long , 64 )
1018
+ if err != nil || longitude < - 180 || longitude > 180 {
1019
+ return errors .New ("invalid longitude: must be a number between -180 and 180" )
995
1020
}
1021
+
1022
+ return nil
1023
+ }
1024
+
1025
+ func withGeoProximityCoordinates (ep * endpoint.Endpoint , geoproximity * route53types.GeoProximityLocation ) bool {
996
1026
if prop , ok := ep .GetProviderSpecificProperty (providerSpecificGeoProximityLocationCoordinates ); ok {
997
1027
coordinates := strings .Split (prop , "," )
998
1028
if len (coordinates ) == 2 {
999
1029
latitude := coordinates [0 ]
1000
1030
longitude := coordinates [1 ]
1031
+ if err := validateCoordinates (latitude , longitude ); err != nil {
1032
+ log .Errorf ("Invalid coordinates %s for name=%s setIdentifier=%s; %v" , prop , ep .DNSName , ep .SetIdentifier , err )
1033
+ return false
1034
+ }
1001
1035
geoproximity .Coordinates = & route53types.Coordinates {
1002
1036
Latitude : aws .String (latitude ),
1003
1037
Longitude : aws .String (longitude ),
1004
1038
}
1005
- useGeoproximity = true
1039
+ return true
1006
1040
} else {
1007
1041
log .Errorf ("Invalid coordinates format for %s: %s; expected format 'latitude,longitude'" , providerSpecificGeoProximityLocationCoordinates , prop )
1008
1042
}
1009
1043
}
1044
+ return false
1045
+ }
1046
+
1047
+ func withGeoProximityLocalZoneGroup (ep * endpoint.Endpoint , geoproximity * route53types.GeoProximityLocation ) bool {
1010
1048
if prop , ok := ep .GetProviderSpecificProperty (providerSpecificGeoProximityLocationLocalZoneGroup ); ok {
1011
1049
geoproximity .LocalZoneGroup = aws .String (prop )
1012
- useGeoproximity = true
1050
+ return true
1013
1051
}
1014
- if useGeoproximity {
1015
- change .ResourceRecordSet .GeoProximityLocation = geoproximity
1052
+ return false
1053
+ }
1054
+
1055
+ func withGeoProximityBias (ep * endpoint.Endpoint , geoproximity * route53types.GeoProximityLocation ) {
1056
+ if prop , ok := ep .GetProviderSpecificProperty (providerSpecificGeoProximityLocationBias ); ok {
1057
+ bias , _ := strconv .ParseInt (prop , 10 , 32 )
1058
+ geoproximity .Bias = aws .Int32 (int32 (bias ))
1016
1059
}
1017
1060
}
1018
1061
0 commit comments