-
Notifications
You must be signed in to change notification settings - Fork 67
/
default.go
107 lines (88 loc) · 3.28 KB
/
default.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* Copyright 2019 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
*
*/
package provider
import (
"github.com/gardener/external-dns-management/pkg/dns"
dnsutils "github.com/gardener/external-dns-management/pkg/dns/utils"
)
////////////////////////////////////////////////////////////////////////////////
// Default Implementation for DNSZoneState
////////////////////////////////////////////////////////////////////////////////
type DefaultDNSZoneState struct {
sets dns.DNSSets
}
func (this *DefaultDNSZoneState) GetDNSSets() dns.DNSSets {
return this.sets
}
func NewDNSZoneState(sets dns.DNSSets) DNSZoneState {
return &DefaultDNSZoneState{sets}
}
func (this *DefaultDNSZoneState) Clone() DNSZoneState {
return NewDNSZoneState(this.sets.Clone())
}
////////////////////////////////////////////////////////////////////////////////
// Default Implementation for DNSHostedZone
////////////////////////////////////////////////////////////////////////////////
type DefaultDNSHostedZone struct {
providerType string // provider type
id string // identifying id for provider api
domain string // base domain for zone
forwarded []string // forwarded sub domains
key string // internal key used by provider (not used by this lib)
isPrivate bool // indicates a private zone
}
func (this *DefaultDNSHostedZone) Key() string {
if this.key != "" {
return this.key
}
return this.id
}
func (this *DefaultDNSHostedZone) ProviderType() string {
return this.providerType
}
func (this *DefaultDNSHostedZone) Id() string {
return this.id
}
func (this *DefaultDNSHostedZone) Domain() string {
return this.domain
}
func (this *DefaultDNSHostedZone) ForwardedDomains() []string {
return this.forwarded
}
func (this *DefaultDNSHostedZone) IsPrivate() bool {
return this.isPrivate
}
func (this *DefaultDNSHostedZone) Match(dnsname string) int {
return Match(this, dnsname)
}
func Match(zone DNSHostedZone, dnsname string) int {
for _, forwardedDomain := range zone.ForwardedDomains() {
if dnsutils.Match(dnsname, forwardedDomain) {
return 0
}
}
if dnsutils.Match(dnsname, zone.Domain()) {
return len(zone.Domain())
}
return 0
}
func NewDNSHostedZone(ptype string, id, domain, key string, forwarded []string, isPrivate bool) DNSHostedZone {
return &DefaultDNSHostedZone{providerType: ptype, id: id, key: key, domain: domain, forwarded: forwarded, isPrivate: isPrivate}
}
func CopyDNSHostedZone(zone DNSHostedZone, forwardedDomains []string) DNSHostedZone {
return &DefaultDNSHostedZone{providerType: zone.ProviderType(), id: zone.Id(), key: zone.Key(),
domain: zone.Domain(), forwarded: forwardedDomains, isPrivate: zone.IsPrivate()}
}