go(localbreach): tweak code,test for multidoc yaml
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
7602c7157e
commit
d9c3fc1d68
@ -4,6 +4,8 @@
|
||||
package localbreach
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
@ -25,27 +27,38 @@ type BreachDataSchema struct {
|
||||
}
|
||||
|
||||
// Load loads local breach data.
|
||||
func Load(path string) (*BreachDataSchema, error) {
|
||||
func Load(path string) (*[]BreachDataSchema, error) {
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
localBreach, err := loadLocalBreach(b)
|
||||
lb, err := loadLocalBreach(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return localBreach, nil
|
||||
return lb, nil
|
||||
}
|
||||
|
||||
func loadLocalBreach(b []byte) (*BreachDataSchema, error) {
|
||||
localBreach := new(BreachDataSchema)
|
||||
func loadLocalBreach(b []byte) (*[]BreachDataSchema, error) {
|
||||
r := bytes.NewReader(b)
|
||||
decoder := yaml.NewDecoder(r)
|
||||
lb := make([]BreachDataSchema, 0)
|
||||
|
||||
err := yaml.Unmarshal(b, localBreach)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var bds BreachDataSchema
|
||||
|
||||
for {
|
||||
if err := decoder.Decode(&bds); err != nil {
|
||||
if err != io.EOF {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
break // get out when there are no more documents to read.
|
||||
}
|
||||
|
||||
lb = append(lb, bds)
|
||||
}
|
||||
|
||||
return localBreach, nil
|
||||
return &lb, nil
|
||||
}
|
||||
|
15
modules/localbreach/testdata/test1.yaml
vendored
15
modules/localbreach/testdata/test1.yaml
vendored
@ -18,4 +18,19 @@ data:
|
||||
- password1
|
||||
- qwertyasdf
|
||||
- 0987654321
|
||||
---
|
||||
name: test breach 2
|
||||
time: 2022-11-12
|
||||
isVerified: false
|
||||
containsPasswds: true
|
||||
containsHashes: false
|
||||
containsUsernames: false
|
||||
containsEmails: true
|
||||
data:
|
||||
emails:
|
||||
- aa@bb.cc
|
||||
- dfjsnlads@gmail.com
|
||||
passwds:
|
||||
- password1
|
||||
- ""
|
||||
...
|
||||
|
Loading…
Reference in New Issue
Block a user