Skip to content

Commit

Permalink
Feat: support wantedList in text input format
Browse files Browse the repository at this point in the history
  • Loading branch information
Loyalsoldier committed Aug 15, 2024
1 parent 4fe0d0f commit f951cbb
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions plugin/plaintext/text_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func newTextIn(action lib.Action, data json.RawMessage) (lib.InputConverter, err
Name string `json:"name"`
URI string `json:"uri"`
InputDir string `json:"inputDir"`
Want []string `json:"wantedList"`
OnlyIPType lib.IPType `json:"onlyIPType"`
}

Expand All @@ -50,13 +51,22 @@ func newTextIn(action lib.Action, data json.RawMessage) (lib.InputConverter, err
return nil, fmt.Errorf("type %s | action %s name & uri must be specified together", typeTextIn, action)
}

// Filter want list
wantList := make(map[string]bool)
for _, want := range tmp.Want {
if want = strings.ToUpper(strings.TrimSpace(want)); want != "" {
wantList[want] = true
}
}

return &textIn{
Type: typeTextIn,
Action: action,
Description: descTextIn,
Name: tmp.Name,
URI: tmp.URI,
InputDir: tmp.InputDir,
Want: wantList,
OnlyIPType: tmp.OnlyIPType,
}, nil
}
Expand All @@ -68,6 +78,7 @@ type textIn struct {
Name string
URI string
InputDir string
Want map[string]bool
OnlyIPType lib.IPType
}

Expand Down Expand Up @@ -175,6 +186,10 @@ func (t *textIn) walkLocalFile(path, name string, entries map[string]*lib.Entry)
}

entryName = strings.ToUpper(entryName)

if len(t.Want) > 0 && !t.Want[entryName] {
return nil
}
if _, found := entries[entryName]; found {
return fmt.Errorf("found duplicated list %s", entryName)
}
Expand Down Expand Up @@ -206,6 +221,11 @@ func (t *textIn) walkRemoteFile(url, name string, entries map[string]*lib.Entry)
}

name = strings.ToUpper(name)

if len(t.Want) > 0 && !t.Want[name] {
return nil
}

entry := lib.NewEntry(name)
if err := t.scanFile(resp.Body, entry); err != nil {
return err
Expand Down

0 comments on commit f951cbb

Please sign in to comment.