@@ -8,7 +8,15 @@ import (
8
8
)
9
9
10
10
// GetStaticRecords returns records that are specified in static YAML file
11
- func (e * Enforcer ) GetStaticRecords () ([]* Record , error ) {
11
+ func (e * Enforcer ) GetStaticRecords (hostr []* Record ) ([]* Record , error ) {
12
+ m := make (map [string ][]* Record )
13
+ for _ , r := range hostr {
14
+ if d , e := m [r .Name ]; e {
15
+ m [r .Name ] = append (d , r )
16
+ } else {
17
+ m [r .Name ] = []* Record {r }
18
+ }
19
+ }
12
20
var records []* Record
13
21
reader := yaml .NewDecoder (e .static )
14
22
for {
@@ -29,12 +37,30 @@ func (e *Enforcer) GetStaticRecords() ([]*Record, error) {
29
37
continue
30
38
}
31
39
for _ , d := range record .Data {
32
- records = append (records , & Record {
33
- Name : record .Name ,
34
- TTL : record .TTL ,
35
- Type : record .Type ,
36
- Data : []string {d },
37
- })
40
+ if record .Type == "ALIAS" {
41
+ if dsts , e := m [d ]; e {
42
+ for _ , dst := range dsts {
43
+ for _ , ds := range dst .Data {
44
+ records = append (records , & Record {
45
+ Name : record .Name ,
46
+ TTL : record .TTL ,
47
+ Type : dst .Type ,
48
+ Data : []string {ds },
49
+ })
50
+ }
51
+ }
52
+ log .Infof ("Added ALIAS %s for %s" , record .Name , d )
53
+ } else {
54
+ log .Warningf ("Found ALIAS %s pointing to non existing host %s" , record .Name , d )
55
+ }
56
+ } else {
57
+ records = append (records , & Record {
58
+ Name : record .Name ,
59
+ TTL : record .TTL ,
60
+ Type : record .Type ,
61
+ Data : []string {d },
62
+ })
63
+ }
38
64
}
39
65
}
40
66
}
0 commit comments