-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Ibm ranges are now correctly fetched
- Loading branch information
Showing
6 changed files
with
235 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,73 @@ | ||
package source | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/Escape-Technologies/cloudfinder/internal/log" | ||
"github.com/Escape-Technologies/cloudfinder/pkg/provider" | ||
) | ||
|
||
type Ibm struct{} | ||
|
||
const ibmFileURL = "https://raw.githubusercontent.com/devanshbatham/ip2cloud/main/data/ibm.txt" | ||
// This url is sourced from: https://ibm.biz/cidr-calculator, itself referenced in the official docs: https://cloud.ibm.com/docs/cloud-infrastructure?topic=cloud-infrastructure-ibm-cloud-ip-ranges | ||
const ibmFileURL = "https://raw.githubusercontent.com/dprosper/cidr-calculator/main/data/datacenters.json" | ||
|
||
type cat []*struct { | ||
CdirBlocks []string `json:"cidr_blocks"` | ||
} | ||
|
||
type ibmJSON struct { | ||
DataCenters []struct { | ||
Public cat `json:"front_end_public_network"` | ||
LoadBalancers cat `json:"load_balancers_ips"` | ||
Service cat `json:"service_network"` | ||
FileBlock cat `json:"file_block"` | ||
Icons cat `json:"icos"` | ||
AdvMon cat `json:"advmon"` | ||
RheLs cat `json:"rhe_ls"` | ||
Ims cat `json:"ims"` | ||
} `json:"data_centers"` | ||
} | ||
|
||
func (a Ibm) GetProvider() provider.Provider { | ||
return provider.Ibm | ||
} | ||
|
||
func (a Ibm) GetIPRanges() []*IPRange { | ||
log.Info("Using static Ibm ip ranges") | ||
log.Info("Fetching ibm ranges") | ||
|
||
ranges := make([]*IPRange, 0) | ||
ibmRanges, err := LoadTextURLToRange(ibmFileURL) | ||
j := &ibmJSON{} | ||
err := LoadFileURLToJSON(ibmFileURL, j) | ||
if err != nil { | ||
log.Fatal("Failed to load text url to range for IBM", err) | ||
log.Fatal("Failed to load json from url for IBM", err) | ||
} | ||
for _, cdir := range ibmRanges { | ||
network, cat := ParseCIDR(cdir) | ||
ranges = append(ranges, &IPRange{ | ||
Network: network, | ||
Cat: cat, | ||
}) | ||
|
||
// Much nesting lol | ||
for _, d := range j.DataCenters { | ||
// convert to map to iterate over fields easily | ||
b, _ := json.Marshal(d) | ||
m := map[string]cat{} | ||
err = json.Unmarshal(b, &m) | ||
if err != nil { | ||
log.Fatal("Failed to load json from url for IBM", err) | ||
} | ||
|
||
for _, c := range m { | ||
for _, cdirs := range c { | ||
for _, cdir := range cdirs.CdirBlocks { | ||
network, cat := ParseCIDR(cdir) | ||
if isPrivateNetwork(network) { | ||
continue | ||
} | ||
ranges = append(ranges, &IPRange{ | ||
Network: network, | ||
Cat: cat, | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return ranges | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
52b8c3cf76f519279f8d1592e351bfbc0a099bc2f8e787a16df3065097f9962a | ||
56bb287f7dbb22a8ba1ccad5e16fe86e8bd3632de2a056b37ed939cd3692ab7f |
Binary file not shown.
Binary file not shown.
Oops, something went wrong.