/
dns.go
44 lines (40 loc) · 1.35 KB
/
dns.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package dns
import (
"context"
"strings"
"testing"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/route53"
route53_types "github.com/aws/aws-sdk-go-v2/service/route53/types"
"github.com/stretchr/testify/require"
)
func GetAWSApiRoute53Client(t *testing.T) *route53.Client {
awsApiLambdaClient := route53.NewFromConfig(GetAWSConfig(t))
return awsApiLambdaClient
}
func GetAWSConfig(t *testing.T) (cfg aws.Config) {
cfg, err := config.LoadDefaultConfig(context.TODO())
require.NoErrorf(t, err, "unable to load SDK config, %v", err)
return cfg
}
func NameNormalize(name string) string {
if !strings.HasSuffix(name, ".") {
name = name + "."
}
return name
}
func GetHostedZoneById(t *testing.T, zone_id string) *route53.GetHostedZoneOutput {
zone, err := GetAWSApiRoute53Client(t).GetHostedZone(context.Background(), &route53.GetHostedZoneInput{
Id: &zone_id,
})
require.NoError(t, err)
return zone
}
func LookupDNSRecordInPublicRoute53ZoneByDNSProtocol(t *testing.T, zone_id string, fullQualifiedRecordName string, recType string) (*route53.TestDNSAnswerOutput, error) {
return GetAWSApiRoute53Client(t).TestDNSAnswer(context.Background(), &route53.TestDNSAnswerInput{
HostedZoneId: &zone_id,
RecordName: &fullQualifiedRecordName,
RecordType: route53_types.RRType(recType),
})
}