-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain.go
More file actions
50 lines (40 loc) · 1.03 KB
/
main.go
File metadata and controls
50 lines (40 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"context"
"fmt"
"os"
"github.com/specterops/dawgs/drivers"
"github.com/specterops/dawgs/drivers/pg"
"github.com/specterops/dawgs/opengraph"
"github.com/specterops/dawgs/util/size"
)
func main() {
connStr := os.Getenv("PGCONN")
if connStr == "" {
connStr = "postgresql://bloodhound:bloodhoundcommunityedition@localhost:5432/bloodhound"
}
dbcfg := drivers.DatabaseConfiguration{}
dbcfg.Connection = connStr
pool, err := pg.NewPool(dbcfg)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to connect: %v\n", err)
os.Exit(1)
}
defer pool.Close()
db := pg.NewDriver(size.Gibibyte, pool)
outFile := "graph_export.json"
if len(os.Args) > 1 {
outFile = os.Args[1]
}
f, err := os.Create(outFile)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to create file: %v\n", err)
os.Exit(1)
}
defer f.Close()
if err := opengraph.Export(context.Background(), db, f); err != nil {
fmt.Fprintf(os.Stderr, "export failed: %v\n", err)
os.Exit(1)
}
fmt.Fprintf(os.Stderr, "exported graph to %s\n", outFile)
}