Skip to content

Commit 0c5fa63

Browse files
committed
Add support for ALIAS to ipplan hosts
1 parent a318bc7 commit 0c5fa63

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

enforcer/records.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (e *Enforcer) GetAllRecords() ([]*Record, error) {
1616
if err != nil {
1717
return nil, err
1818
}
19-
static, err := e.GetStaticRecords()
19+
static, err := e.GetStaticRecords(hosts)
2020
if err != nil {
2121
return nil, err
2222
}

enforcer/static.go

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ import (
88
)
99

1010
// 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+
}
1220
var records []*Record
1321
reader := yaml.NewDecoder(e.static)
1422
for {
@@ -29,12 +37,30 @@ func (e *Enforcer) GetStaticRecords() ([]*Record, error) {
2937
continue
3038
}
3139
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+
}
3864
}
3965
}
4066
}

0 commit comments

Comments
 (0)