helper.go raw
1 package record
2
3 import (
4 "github.com/ultradns/ultradns-go-sdk/pkg/record/dirpool"
5 "github.com/ultradns/ultradns-go-sdk/pkg/record/pool"
6 "github.com/ultradns/ultradns-go-sdk/pkg/record/rdpool"
7 "github.com/ultradns/ultradns-go-sdk/pkg/record/sbpool"
8 "github.com/ultradns/ultradns-go-sdk/pkg/record/sfpool"
9 "github.com/ultradns/ultradns-go-sdk/pkg/record/slbpool"
10 "github.com/ultradns/ultradns-go-sdk/pkg/record/tcpool"
11 "github.com/ultradns/ultradns-go-sdk/pkg/rrset"
12 )
13
14 func getPoolSchema(poolType string) string {
15 var poolSchema = map[string]string{
16 pool.RD: rdpool.Schema,
17 pool.SF: sfpool.Schema,
18 pool.SLB: slbpool.Schema,
19 pool.SB: sbpool.Schema,
20 pool.TC: tcpool.Schema,
21 pool.DIR: dirpool.Schema,
22 }
23
24 return poolSchema[poolType]
25 }
26
27 func validatePoolProfile(rrSet *rrset.RRSet) error {
28 if rrSet.Profile == nil {
29 return nil
30 }
31
32 rrSet.Profile.SetContext()
33
34 switch rrSet.Profile.GetContext() {
35 case rdpool.Schema:
36 return pool.ValidatePoolOrder(rrSet.Profile.(*rdpool.Profile).Order)
37 case sfpool.Schema:
38 return validateSFPoolProfile(rrSet.Profile.(*sfpool.Profile))
39 case slbpool.Schema:
40 return validateSLBPoolProfile(rrSet.Profile.(*slbpool.Profile))
41 case sbpool.Schema:
42 return validateSBPoolProfile(rrSet.Profile.(*sbpool.Profile))
43 case tcpool.Schema:
44 return pool.ValidatePoolRecordState(rrSet.Profile.(*tcpool.Profile).RDataInfo)
45 case dirpool.Schema:
46 return pool.ValidateConflictResolve(rrSet.Profile.(*dirpool.Profile).ConflictResolve)
47 }
48
49 return nil
50 }
51
52 func validateSFPoolProfile(profile *sfpool.Profile) error {
53 if err := pool.ValidateMonitorMethod(profile.Monitor); err != nil {
54 return err
55 }
56
57 if err := pool.ValidateRegionFailureSensitivity(profile.RegionFailureSensitivity); err != nil {
58 return err
59 }
60
61 return nil
62 }
63
64 func validateSLBPoolProfile(profile *slbpool.Profile) error {
65 if err := pool.ValidateMonitorMethod(profile.Monitor); err != nil {
66 return err
67 }
68
69 if err := pool.ValidateRegionFailureSensitivity(profile.RegionFailureSensitivity); err != nil {
70 return err
71 }
72
73 if err := pool.ValidateResponseMethod(profile.ResponseMethod); err != nil {
74 return err
75 }
76
77 if err := pool.ValidateServingPreference(profile.ServingPreference); err != nil {
78 return err
79 }
80
81 return nil
82 }
83
84 func validateSBPoolProfile(profile *sbpool.Profile) error {
85 if err := pool.ValidatePoolOrder(profile.Order); err != nil {
86 return err
87 }
88
89 if err := pool.ValidatePoolRecordState(profile.RDataInfo); err != nil {
90 return err
91 }
92
93 return nil
94 }
95