-
Notifications
You must be signed in to change notification settings - Fork 67
/
routingpolicy.go
71 lines (64 loc) · 1.88 KB
/
routingpolicy.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package dns
import (
"fmt"
)
const (
// RoutingPolicyWeighted is a weighted routing policy (supported for AWS Route 53 and Google CloudDNS)
RoutingPolicyWeighted = "weighted"
// RoutingPolicyLatency is a latency based routing policy (supported for AWS Route 53)
RoutingPolicyLatency = "latency"
// RoutingPolicyGeoLocation is a geolocation based routing policy (supported for AWS Route 53 and Google CloudDNS)
RoutingPolicyGeoLocation = "geolocation"
// RoutingPolicyIPBased is an IP based routing policy (supported for AWS Route 53)
RoutingPolicyIPBased = "ip-based"
// RoutingPolicyFailover is failover routing policy (supported for AWS Route 53)
RoutingPolicyFailover = "failover"
)
type RoutingPolicy struct {
Type string
Parameters map[string]string
}
func NewRoutingPolicy(typ string, keyvalues ...string) *RoutingPolicy {
policy := &RoutingPolicy{Type: typ, Parameters: map[string]string{}}
for i := 0; i < len(keyvalues)-1; i += 2 {
policy.Parameters[keyvalues[i]] = keyvalues[i+1]
}
return policy
}
func (p *RoutingPolicy) Clone() *RoutingPolicy {
if p == nil {
return nil
}
copy := &RoutingPolicy{Type: p.Type, Parameters: map[string]string{}}
for k, v := range p.Parameters {
copy.Parameters[k] = v
}
return copy
}
func (p *RoutingPolicy) CheckParameterKeys(keys, optionalKeys []string) error {
for _, k := range keys {
if _, ok := p.Parameters[k]; !ok {
return fmt.Errorf("Missing parameter key %s", k)
}
}
if len(keys) != len(p.Parameters) {
outer:
for k := range p.Parameters {
for _, k2 := range keys {
if k == k2 {
continue outer
}
}
for _, k2 := range optionalKeys {
if k == k2 {
continue outer
}
}
return fmt.Errorf("Unsupported parameter key %s", k)
}
}
return nil
}