styx/schema.go

128 lines
1.4 KiB
Go

package main
import (
"context"
"fmt"
"github.com/dgraph-io/dgo"
"github.com/dgraph-io/dgo/protos/api"
"google.golang.org/grpc"
)
func ConnectToDgraph() error {
conn, err := grpc.Dial("localhost:9080", grpc.WithInsecure())
if err != nil {
return err
}
defer conn.Close()
dgraphClient := dgo.NewDgraphClient(api.NewDgraphClient(conn))
fmt.Println("pouet")
err = setupDgraphSchema(dgraphClient)
if err != nil {
return err
}
return nil
}
func setupDgraphSchema(c *dgo.Dgraph) error {
err := c.Alter(context.Background(), &api.Operation{
DropAll: true,
Schema: `
ID: string @index(term) .
Type: string @index(term) .
Data: string .
NodeOneID: [uid] .
NodeTwoID: [uid] .
Source: string @index(term) .
Timestamp: string .
Created: dateTime .
Modified: dateTime .
type Node {
ID
Type
Data
Created
Modified
}
type Edge {
ID
NodeOneID
NodeTwoID
Timestamp
Source
}
Fingerprint: string .
NotBefore: string .
NotAfter: string .
CN: string .
SourceName: string .
SerialNumber: string .
BasicConstraints: string .
Chain: [uid] .
Data: [uid] .
type CertNode {
ID
Fingerprint
NotBefore
NotAfter
CN
SourceName
SerialNumber
BasicConstraints
Chain
}
type CertRaw {
ID
Type
Created
Modified
Data
}
type PasteNode {
ID
Type
Created
Modified
Data
}
Meta: [uid] .
Full: string .
type FullPaste {
Meta
Full
}
type ShodanNode {
ID
Type
Data
Created
Modified
}
type BalboaNode {
ID
Type
Data
Created
Modified
}
`})
if err != nil {
return err
}
return nil
}