-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (40 loc) · 925 Bytes
/
main.go
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
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/nag0yan/sgviz/internal/graph"
"github.com/nag0yan/sgviz/internal/model"
"github.com/nag0yan/sgviz/internal/renderer"
)
func main() {
// Load json
if len(os.Args) < 2 {
fmt.Fprintf(os.Stderr, "Usage: sgviz <json file>\n")
return
}
fileName := os.Args[1]
data, err := os.ReadFile(fileName)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to read file: %v\n", err)
return
}
var res model.CLIResponse
err = json.Unmarshal(data, &res)
if err != nil {
fmt.Fprintf(os.Stderr, "Invalid json: %v\n", err)
return
}
sgs := res.SecurityGroups
g, err := graph.GenerateGraph(sgs)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to generate graph: %v\n", err)
return
}
g = g.AggregateNodes()
err = renderer.GenerateMarkDown(os.Stdout, g)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to generate markdown: %v\n", err)
return
}
}