@@ -2,24 +2,31 @@ package internal
22
33import (
44 "context"
5+ "errors"
56 "fmt"
67 "regexp"
78 "strconv"
89
910 domainsV2 "github.com/selectel/domains-go/pkg/v2"
11+ "golang.org/x/net/idna"
1012)
1113
12- var ErrRrsetNotFound = fmt . Errorf ("rrset not found" )
14+ var ErrRrsetNotFound = errors . New ("rrset not found" )
1315
1416func GetRrsetByNameAndType (ctx context.Context , client domainsV2.DNSClient [domainsV2.Zone , domainsV2.RRSet ], zoneID , rrsetName , rrsetType string ) (* domainsV2.RRSet , error ) {
17+ rrsetNameUnicode , err := idna .ToUnicode (rrsetName )
18+ if err != nil {
19+ return nil , fmt .Errorf ("convert rrset name to unicode: %w" , err )
20+ }
21+
1522 optsForSearchRrset := map [string ]string {
16- "name" : rrsetName ,
23+ "name" : rrsetNameUnicode ,
1724 "rrset_types" : rrsetType ,
1825 "limit" : "100" ,
1926 "offset" : "0" ,
2027 }
2128
22- regexpRRSetWithDotOrNot , err := regexp .Compile (fmt .Sprintf ("^%s.?" , rrsetName ))
29+ regexpRRSetWithDotOrNot , err := regexp .Compile (fmt .Sprintf ("^%s.?" , rrsetNameUnicode ))
2330 if err != nil {
2431 return nil , fmt .Errorf ("compile regexp: %w" , err )
2532 }
@@ -29,11 +36,13 @@ func GetRrsetByNameAndType(ctx context.Context, client domainsV2.DNSClient[domai
2936 if err != nil {
3037 return nil , fmt .Errorf ("list rrsets: %w" , err )
3138 }
39+
3240 for _ , rrset := range rrsets .GetItems () {
3341 if regexpRRSetWithDotOrNot .MatchString (rrset .Name ) && string (rrset .Type ) == rrsetType {
3442 return rrset , nil
3543 }
3644 }
45+
3746 optsForSearchRrset ["offset" ] = strconv .Itoa (rrsets .GetNextOffset ())
3847 if rrsets .GetNextOffset () == 0 {
3948 break
0 commit comments