sigs.k8s.io/external-dns@v0.14.1/provider/azure/common.go (about) 1 /* 2 Copyright 2017 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 //nolint:staticcheck // Required due to the current dependency on a deprecated version of azure-sdk-for-go 18 package azure 19 20 import ( 21 "fmt" 22 "strconv" 23 "strings" 24 25 "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" 26 dns "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/dns/armdns" 27 privatedns "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/privatedns/armprivatedns" 28 ) 29 30 // Helper function (shared with test code) 31 func parseMxTarget[T dns.MxRecord | privatedns.MxRecord](mxTarget string) (T, error) { 32 targetParts := strings.SplitN(mxTarget, " ", 2) 33 if len(targetParts) != 2 { 34 return T{}, fmt.Errorf("mx target needs to be of form '10 example.com'") 35 } 36 37 preferenceRaw, exchange := targetParts[0], targetParts[1] 38 preference, err := strconv.ParseInt(preferenceRaw, 10, 32) 39 if err != nil { 40 return T{}, fmt.Errorf("invalid preference specified") 41 } 42 43 return T{ 44 Preference: to.Ptr(int32(preference)), 45 Exchange: to.Ptr(exchange), 46 }, nil 47 }