-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathranges.go
44 lines (37 loc) · 1.01 KB
/
ranges.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
package main
import (
"encoding/json"
"net"
"os"
log "github.com/sirupsen/logrus"
)
type Organisation struct {
Name string `json:"name"`
CIDRList []string `json:"ranges"`
Networks []*net.IPNet
}
func loadRanges(config *Config) {
log.WithField("filename", config.OrganisationsFile).Info("Loading ip ranges from a seperate file")
config.Organisations = nil
data, err := os.ReadFile(config.OrganisationsFile)
if err != nil {
log.Fatal(err)
}
err = json.Unmarshal(data, &config.Organisations)
if err != nil {
log.Fatal(err)
}
for i := range config.Organisations {
for _, cidr := range config.Organisations[i].CIDRList {
_, net, err := net.ParseCIDR(cidr)
if err != nil {
log.WithFields(log.Fields{
"organisation": config.Organisations[i].Name,
"cidr": cidr,
}).Error("Could not parse given CIDR notation")
}
config.Organisations[i].Networks = append(config.Organisations[i].Networks, net)
}
}
log.Debugf("Loaded %d organisations", len(config.Organisations))
}