2020-01-22 15:49:52 +01:00
|
|
|
package parser
|
|
|
|
|
2020-01-26 17:27:20 +01:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io/ioutil"
|
2020-01-28 16:03:46 +01:00
|
|
|
"os"
|
2020-01-26 17:27:20 +01:00
|
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"gitlab.dcso.lolcat/LABS/styx/models"
|
|
|
|
"gitlab.dcso.lolcat/LABS/styx/utils"
|
|
|
|
)
|
|
|
|
|
2020-01-22 15:49:52 +01:00
|
|
|
// read node recieved on kafka
|
|
|
|
// create a node in the node file
|
|
|
|
// save domains in another file with node ID
|
|
|
|
|
|
|
|
// parallel routine
|
|
|
|
// look throught domain names and if find some that exists already, create the
|
|
|
|
// edge file
|
|
|
|
|
|
|
|
const (
|
|
|
|
NodesFilename = "nodes.json"
|
|
|
|
EdgesFilename = "edges.json"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ParseEvent(domains []string) {
|
2020-01-26 17:27:20 +01:00
|
|
|
nodeFile, err := ioutil.ReadFile(NodesFilename)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Error(err)
|
|
|
|
}
|
|
|
|
nodeDatas := []models.Node{}
|
|
|
|
|
|
|
|
if err := json.Unmarshal(nodeFile, &nodeDatas); err != nil {
|
|
|
|
logrus.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, node := range nodeDatas {
|
|
|
|
utils.SaveDomains(node.Data.Data.LeafCert.AllDomains)
|
|
|
|
}
|
2020-01-22 15:49:52 +01:00
|
|
|
|
|
|
|
// saveDomains()
|
|
|
|
// go findDomainEdges()
|
|
|
|
}
|
|
|
|
|
2020-01-28 16:03:46 +01:00
|
|
|
func SaveDomains(domains []string) {
|
|
|
|
f, err := os.OpenFile("domains.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Error(err)
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
for _, d := range domains {
|
|
|
|
if _, err := f.WriteString(d + ","); err != nil {
|
|
|
|
logrus.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 15:49:52 +01:00
|
|
|
// Helpers
|