Skip to content

Commit

Permalink
fix: digital ocean csv
Browse files Browse the repository at this point in the history
  • Loading branch information
nohehf committed Oct 22, 2024
1 parent 5af197b commit 13b93e3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions internal/source/source_digitalocean.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,29 @@ func (a Digitalocean) GetProvider() provider.Provider {
return provider.Digitalocean
}

// Digital ocean csv has been broken, with lines containing less than the usual 5 fields
// This will remove incorrect lines
func fixCsv(in string) string {
var result []string
lines := strings.Split(in, "\n")

for _, line := range lines {
if strings.Count(line, ",") == 4 { //nolint:mnd
result = append(result, line)
}
}

return strings.Join(result, "\n")
}

func (a Digitalocean) GetIPRanges() []*IPRange {
log.Info("Fetching do ip ranges from %s", doFileURL)

content, err := FileURLToString(doFileURL)
if err != nil {
log.Fatal("Failed to read digitalocean ip ranges", err)
}
content = fixCsv(content)
data, err := csv.NewReader(strings.NewReader(content)).ReadAll()
if err != nil {
log.Fatal("Failed to read csv", err)
Expand Down

0 comments on commit 13b93e3

Please sign in to comment.