-
Notifications
You must be signed in to change notification settings - Fork 1
/
oracle_origin.go
74 lines (63 loc) · 1.43 KB
/
oracle_origin.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
package main
import (
"sort"
"strings"
)
type oraclePublicIpRanges struct {
Regions []struct {
Region string `json:"region"`
Cidrs []struct {
Cidr string `json:"cidr"`
Tags []string `json:"tags"`
} `json:"cidrs"`
} `json:"regions"`
}
type OracleOrigin struct {
httpJson HttpJson
Emitter
}
func OracleOriginCreate() (*OracleOrigin, error) {
return &OracleOrigin{
httpJson: HttpJsonCreate(),
Emitter: Emitter{
id: "oracle",
},
}, nil
}
func (o *OracleOrigin) Run(ipv4Only bool) error {
header := Header{
general: `#
# IP to Oracle mapping
#
# https://docs.oracle.com/en-us/iaas/tools/public_ip_ranges.json
#
`,
columns: "# cidr Oracle/service[,service]*/region\n",
}
if err := o.Header(header); err != nil {
return err
}
ranges := oraclePublicIpRanges{}
err := o.httpJson.Fetch("https://docs.oracle.com/en-us/iaas/tools/public_ip_ranges.json", "GET", &ranges)
if err != nil {
return err
}
blocks := make(Blocks, 0)
for _, region := range ranges.Regions {
for _, cidr := range region.Cidrs {
// Multiple tags for a given cidr, best we can do is sort and comma seperate them...
sort.Strings(cidr.Tags)
value := "Oracle/" + strings.Join(cidr.Tags, ",") + "/" + region.Region
block, err := BlockCreateWithCidr(&cidr.Cidr, &value)
if err != nil {
return err
}
blocks = append(blocks, block)
}
}
sort.Sort(blocks)
for _, block := range blocks {
o.Emit(block)
}
return o.Done()
}