Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions annotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/csv"
"fmt"
"os/signal"
"reflect"
"slices"
"syscall"
"time"
Expand Down Expand Up @@ -246,6 +247,19 @@ func AnnotateWrite(path string, out <-chan string, wg *sync.WaitGroup) {
log.Debug("write thread finished")
}

func isPtrNil(i any) bool {
if i == nil {
return true
}
val := reflect.ValueOf(i)
switch val.Kind() {
case reflect.Pointer, reflect.Interface, reflect.Slice, reflect.Map:
return val.IsNil()
default:
return false
}
}

func AnnotateWorker(conf *GlobalConf, a Annotator, inChan <-chan inProcessIP,
outChan chan<- inProcessIP, fieldName string, wg *sync.WaitGroup, i int) {
name := a.GetFieldName()
Expand All @@ -257,9 +271,18 @@ func AnnotateWorker(conf *GlobalConf, a Annotator, inChan <-chan inProcessIP,
for inProcess := range inChan {
if fieldName != "" && slices.Contains([]string{"json", "csv"}, conf.InputFileType) {
p := inProcess.Out[fieldName].(map[string]interface{})
p[name] = a.Annotate(inProcess.Ip)
res := a.Annotate(inProcess.Ip)
if isPtrNil(res) {
res = struct{}{} // Don't return null, breaks downstream JSON parsing
}
p[name] = res

} else {
inProcess.Out[name] = a.Annotate(inProcess.Ip)
res := a.Annotate(inProcess.Ip)
if isPtrNil(res) {
res = struct{}{} // Don't return null, breaks downstream JSON parsing
}
inProcess.Out[name] = res
}
outChan <- inProcess
}
Expand Down
1 change: 0 additions & 1 deletion censys.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ var censysAPIHostLookupURL = "https://api.platform.censys.io/v3/global/asset/hos
// Annotate performs a Censys host lookup for the given IP address and returns the results.
// If an error occurs or a lookup fails, it returns nil
func (a *CensysAnnotator) Annotate(ip net.IP) interface{} {

req, err := http.NewRequest("GET", censysAPIHostLookupURL+ip.String(), nil)
if err != nil {
// If we can't even form a request, we'll fail to enrich anything. Erroring out.
Expand Down
Loading