diff options
Diffstat (limited to 'plugin')
| -rw-r--r-- | plugin/plaintext/common_in.go | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/plugin/plaintext/common_in.go b/plugin/plaintext/common_in.go index cc7728b1..f8253519 100644 --- a/plugin/plaintext/common_in.go +++ b/plugin/plaintext/common_in.go @@ -209,11 +209,37 @@ func (t *TextIn) scanFileForJSONIn(reader io.Reader, entry *lib.Entry) error { path = strings.TrimSpace(path) result := gjson.GetBytes(data, path) - for _, cidr := range result.Array() { - if err := entry.AddPrefix(cidr.String()); err != nil { + if err := t.processJSONResult(result, entry); err != nil { + return fmt.Errorf("❌ [type %s | action %s] failed to process JSON: %v", t.Type, t.Action, err) + } + } + + return nil +} + +func (t *TextIn) processJSONResult(result gjson.Result, entry *lib.Entry) error { + switch { + case !result.Exists(): + return fmt.Errorf("invaild IP address or CIDR (value not exist), please check your specified JSON path or JSON source") + + case result.Type == gjson.String: + cidr := strings.TrimSpace(result.String()) + if cidr == "" { + return fmt.Errorf("empty string, please check your specified JSON path or JSON source") + } + if err := entry.AddPrefix(cidr); err != nil { + return err + } + + case result.IsArray(): + for _, item := range result.Array() { + if err := t.processJSONResult(item, entry); err != nil { return err } } + + default: + return fmt.Errorf("invaild IP address or CIDR, please check your specified JSON path or JSON source") } return nil |
