styx/parser/main.go
2020-01-28 16:03:46 +01:00

59 lines
1.1 KiB
Go

package parser
import (
"encoding/json"
"io/ioutil"
"os"
"github.com/sirupsen/logrus"
"gitlab.dcso.lolcat/LABS/styx/models"
"gitlab.dcso.lolcat/LABS/styx/utils"
)
// 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) {
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)
}
// saveDomains()
// go findDomainEdges()
}
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)
}
}
}
// Helpers