From f79ce9ec0f05738a4d8ce96bceff6dd9ba79fb9c Mon Sep 17 00:00:00 2001 From: Denys Vitali Date: Sun, 27 Sep 2020 11:05:15 +0200 Subject: [PATCH 1/2] wip: parse yml --- cmd/parse/main.go | 81 ++++++++++++++++++++++++++++++++++++ diagram/data.go | 19 +++++++++ diagram/diagram.go | 68 +++++++++++++++++++++++++++--- diagram/diagram_test.go | 30 +++++++++++++ diagram/options.go | 8 ++++ diagram/parse.go | 34 +++++++++++++++ go.mod | 7 ++-- go.sum | 75 +++++---------------------------- test/assets/parse/ymls/1.yml | 37 ++++++++++++++++ 9 files changed, 286 insertions(+), 73 deletions(-) create mode 100644 cmd/parse/main.go create mode 100644 diagram/data.go create mode 100644 diagram/diagram_test.go create mode 100644 diagram/parse.go create mode 100644 test/assets/parse/ymls/1.yml diff --git a/cmd/parse/main.go b/cmd/parse/main.go new file mode 100644 index 00000000..a2e7d22c --- /dev/null +++ b/cmd/parse/main.go @@ -0,0 +1,81 @@ +package main + +import ( + "github.com/alexflint/go-arg" + "github.com/blushft/go-diagrams/diagram" + "github.com/blushft/go-diagrams/nodes/gcp" + "github.com/blushft/go-diagrams/nodes/generic" + "github.com/sirupsen/logrus" + "log" + "os" +) + +func diag1(){ + d, err := diagram.New(diagram.Filename("app"), diagram.Label("App"), diagram.Direction("LR")) + if err != nil { + log.Fatal(err) + } + + dns := gcp.Network.Dns(diagram.NodeLabel("DNS")) + lb := gcp.Network.LoadBalancing(diagram.NodeLabel("NLB")) + cache := gcp.Database.Memorystore(diagram.NodeLabel("Cache")) + db := gcp.Database.Sql(diagram.NodeLabel("Database")) + + dc := diagram.NewGroup("GCP") + dc.NewGroup("services"). + Label("Service Layer"). + Add( + gcp.Compute.ComputeEngine(diagram.NodeLabel("Server 1")), + gcp.Compute.ComputeEngine(diagram.NodeLabel("Server 2")), + gcp.Compute.ComputeEngine(diagram.NodeLabel("Server 3")), + ). + ConnectAllFrom(lb.ID(), diagram.Forward()). + ConnectAllTo(cache.ID(), diagram.Forward()) + + dc.NewGroup("data").Label("Data Layer").Add(cache, db).Connect(cache, db) + + d.Connect(dns, lb, diagram.Forward()).Group(dc) + + if err := d.Render(); err != nil { + log.Fatal(err) + } +} + +func diag2(){ + d, err := diagram.New(diagram.Label("my-diagram"), diagram.Filename("diagram")) + if err != nil { + log.Fatal(err) + } + + fw := generic.Network.Firewall().Label("fw") + sw := generic.Network.Switch().Label("sw") + + d.Connect(fw, sw) + + if err := d.Render(); err != nil { + log.Fatal(err) + } +} + +var args struct { + Input string `arg:"-i" help:"Input file path (e.g: /tmp/1.yml)"` + Output string `arg:"-o" help:"Output directory"` +} + +func main(){ + arg.MustParse(&args) + + if args.Input == "" { + logrus.Fatal("Input file not specified") + } + + _, err := os.Open(args.Input) + if err != nil { + logrus.Fatalf("unable to open input file: %v", err) + } + + _, err = os.Stat(args.Output) + if err != nil { + logrus.Fatal(err) + } +} diff --git a/diagram/data.go b/diagram/data.go new file mode 100644 index 00000000..ac4a6e59 --- /dev/null +++ b/diagram/data.go @@ -0,0 +1,19 @@ +package diagram + +type NodeData struct { + Name string `yaml:"name"` + Label string `yaml:"label"` + Type string `yaml:"type"` + Nodes []NodeData `yaml:"nodes"` + ConnectTo []string `yaml:"connectTo"` + ConnectFrom []string `yaml:"connectFrom"` + ConnectAllTo []string `yaml:"connectAllTo"` + ConnectAllFrom []string `yaml:"connectAllFrom"` + BackgroundColor string `yaml:"backgroundColor"` +} + +type DiagramData struct { + Direction string `yaml:"direction" default:"LTR"` + Label string `yaml:"label"` + Nodes []NodeData `yaml:"nodes"` +} diff --git a/diagram/diagram.go b/diagram/diagram.go index af0e8e7b..1e13cbd3 100644 --- a/diagram/diagram.go +++ b/diagram/diagram.go @@ -2,11 +2,10 @@ package diagram import ( "errors" + graphviz "github.com/awalterschulze/gographviz" "io/ioutil" "os" "path/filepath" - - graphviz "github.com/awalterschulze/gographviz" ) type Connector interface { @@ -16,9 +15,7 @@ type Connector interface { type Diagram struct { options Options - g *graphviz.Escape - root *Group } @@ -82,6 +79,10 @@ func (d *Diagram) Close() error { return nil } +func (d *Diagram) Parse(file *os.File) error { + return d.parse(file) +} + func (d *Diagram) Render() error { return d.render() } @@ -126,6 +127,63 @@ func (d *Diagram) renderOutput() error { func (d *Diagram) saveDot() error { fname := filepath.Join(d.options.Name, d.options.FileName+".dot") + return ioutil.WriteFile(fname, []byte(d.g.String()), 0644) +} + +func (d *Diagram) interpretYML(yml *DiagramData) error { + if yml.Label != "" { + d.options.Label = yml.Label + } - return ioutil.WriteFile(fname, []byte(d.g.String()), os.ModePerm) + if yml.Direction != "" { + d.options.Direction = yml.Direction + } + + for _, v := range yml.Nodes { + parsedNode := d.parseNode(v) + switch parsedNode.(type) { + case *Node: + d.Add(parsedNode.(*Node)) + case *Group: + d.Group(parsedNode.(*Group)) + } + } + + return nil } + +func (d *Diagram) parseNode(v NodeData) interface{} { + switch v.Type { + case "Group": + groupNode := NewGroup(v.Name) + if v.Label != "" { + groupNode.Label(v.Label) + } + + if v.BackgroundColor != "" { + groupNode.BackgroundColor(v.BackgroundColor) + } + + for _, child := range v.Nodes { + parsedNode := d.parseNode(child) + switch parsedNode.(type) { + case *Node: + groupNode.Add(parsedNode.(*Node)) + case *Group: + groupNode.Group(parsedNode.(*Group)) + } + } + return groupNode + /*case "gcp.Network.DNS": + // TODO: find a better way to do the mapping + node := gcp.Network.Dns() + if v.Label != "" { + node.Label(v.Label) + } + return node*/ + default: + panic("unimplemented " + v.Type) + } + + return nil +} \ No newline at end of file diff --git a/diagram/diagram_test.go b/diagram/diagram_test.go new file mode 100644 index 00000000..418c7c86 --- /dev/null +++ b/diagram/diagram_test.go @@ -0,0 +1,30 @@ +package diagram_test + +import ( + "github.com/blushft/go-diagrams/diagram" + "os" + "testing" +) + +func TestDiagramParse(t *testing.T){ + file, err := os.Open("../test/assets/parse/ymls/1.yml") + if err != nil { + t.Fatal(err) + } + d, err := diagram.New(diagram.Label("my-diagram"), + diagram.DirName("/tmp/diagrams-1"), + diagram.Filename("1")) + if err != nil { + t.Fatal(err) + } + + err = d.Parse(file) + if err != nil { + t.Fatal(err) + } + + err = d.Render() + if err != nil { + t.Fatal(err) + } +} diff --git a/diagram/options.go b/diagram/options.go index 30a587f7..266f78a9 100644 --- a/diagram/options.go +++ b/diagram/options.go @@ -1,12 +1,14 @@ package diagram import ( + "os" "strconv" ) type Options struct { Name string FileName string + InputFile *os.File OutFormat string Direction string CurveStyle string @@ -72,6 +74,12 @@ func Filename(f string) Option { } } +func DirName(d string) Option { + return func(o *Options) { + o.Name = d + } +} + func Label(l string) Option { return func(o *Options) { o.Label = l diff --git a/diagram/parse.go b/diagram/parse.go new file mode 100644 index 00000000..9646b8a2 --- /dev/null +++ b/diagram/parse.go @@ -0,0 +1,34 @@ +package diagram + +import ( + "fmt" + "gopkg.in/yaml.v3" + "os" +) + +func (d *Diagram) parseYML(inputFile *os.File) (*DiagramData, error) { + var decodedYML *DiagramData + + decoder := yaml.NewDecoder(inputFile) + decoder.KnownFields(true) + err := decoder.Decode(&decodedYML) + + if err != nil { + return nil, err + } + + return decodedYML, nil +} + +func (d *Diagram) parse(inputFile *os.File) error { + if inputFile == nil { + return fmt.Errorf("input file not specified") + } + + yml, err := d.parseYML(inputFile) + if err != nil { + return err + } + + return d.interpretYML(yml) +} diff --git a/go.mod b/go.mod index 8bf738ed..9974b59c 100644 --- a/go.mod +++ b/go.mod @@ -3,14 +3,13 @@ module github.com/blushft/go-diagrams go 1.14 require ( - github.com/UnnoTed/fileb0x v1.1.4 // indirect + github.com/alexflint/go-arg v1.3.0 github.com/awalterschulze/gographviz v0.0.0-20200901124122-0eecad45bd71 github.com/dave/jennifer v1.4.1 - github.com/davecgh/go-spew v1.1.1 github.com/google/uuid v1.1.2 github.com/iancoleman/strcase v0.1.1 - github.com/pkg/errors v0.9.1 + github.com/sirupsen/logrus v1.6.0 github.com/stretchr/testify v1.6.1 - golang.org/x/exp v0.0.0-20200908183739-ae8ad444f925 // indirect golang.org/x/net v0.0.0-20190620200207-3b0461eec859 + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c ) diff --git a/go.sum b/go.sum index b289484e..b254645e 100644 --- a/go.sum +++ b/go.sum @@ -1,90 +1,37 @@ -dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/UnnoTed/fileb0x v1.1.4 h1:IUgFzgBipF/ujNx9wZgkrKOF3oltUuXMSoaejrBws+A= -github.com/UnnoTed/fileb0x v1.1.4/go.mod h1:X59xXT18tdNk/D6j+KZySratBsuKJauMtVuJ9cgOiZs= +github.com/alexflint/go-arg v1.3.0 h1:UfldqSdFWeLtoOuVRosqofU4nmhI1pYEbT4ZFS34Bdo= +github.com/alexflint/go-arg v1.3.0/go.mod h1:9iRbDxne7LcR/GSvEr7ma++GLpdIU1zrghf2y2768kM= +github.com/alexflint/go-scalar v1.0.0 h1:NGupf1XV/Xb04wXskDFzS0KWOLH632W/EO4fAFi+A70= +github.com/alexflint/go-scalar v1.0.0/go.mod h1:GpHzbCOZXEKMEcygYQ5n/aa4Aq84zbxjy3MxYW0gjYw= github.com/awalterschulze/gographviz v0.0.0-20200901124122-0eecad45bd71 h1:m3N1Fv5vE5IcxuTOGFGGV0grrVFHV8UY2SV0wSBXAC8= github.com/awalterschulze/gographviz v0.0.0-20200901124122-0eecad45bd71/go.mod h1:/ynarkO/43wP/JM2Okn61e8WFMtdbtA8he7GJxW+SFM= -github.com/bmatcuk/doublestar v1.1.1 h1:YroD6BJCZBYx06yYFEWvUuKVWQn3vLLQAVmDmvTSaiQ= -github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= github.com/dave/jennifer v1.4.1 h1:XyqG6cn5RQsTj3qlWQTKlRGAyrTcsk1kUmWdZBzRjDw= github.com/dave/jennifer v1.4.1/go.mod h1:7jEdnm+qBcxl8PC0zyp7vxcpSRnzXSt9r39tpTVGlwA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/gizak/termui/v3 v3.1.0 h1:ZZmVDgwHl7gR7elfKf1xc4IudXZ5qqfDh4wExk4Iajc= -github.com/gizak/termui/v3 v3.1.0/go.mod h1:bXQEBkJpzxUAKf0+xq9MSWAvWZlE7c+aidmyFlkYTrY= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/iancoleman/strcase v0.1.1 h1:2I+LRClyCYB7JgZb9U0k75VHUiQe9RfknRqDyUfzp7k= github.com/iancoleman/strcase v0.1.1/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE= -github.com/karrick/godirwalk v1.7.8 h1:VfG72pyIxgtC7+3X9CMHI0AOl4LwyRAg98WAgsvffi8= -github.com/karrick/godirwalk v1.7.8/go.mod h1:2c9FRhkDxdIbgkOnCEvnSWs71Bhugbl46shStcFDJ34= -github.com/labstack/echo v3.2.1+incompatible h1:J2M7YArHx4gi8p/3fDw8tX19SXhBCoRpviyAZSN3I88= -github.com/labstack/echo v3.2.1+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s= -github.com/labstack/gommon v0.2.7 h1:2qOPq/twXDrQ6ooBGrn3mrmVOC+biLlatwgIu8lbzRM= -github.com/labstack/gommon v0.2.7/go.mod h1:/tj9csK2iPSBvn+3NLM9e52usepMtrd5ilFYA+wQNJ4= -github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4= -github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs= -github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= -github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4= -github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= -github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= -github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4= -github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= -github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d h1:x3S6kxmy49zXVVyhcnrFqxvNVCBPb2KZ9hV2RBdS840= -github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8= +github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= +github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= -github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4 h1:gKMu1Bf6QINDnvyZuTaACm9ofY+PRh+5vFz4oxBZeF8= -github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4/go.mod h1:50wTf68f99/Zt14pr046Tgt3Lp2vLyFZKzbFXTOabXw= -golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20200908183739-ae8ad444f925 h1:5XVKs2rlCg8EFyRcvO8/XFwYxh1oKJO1Q3X5vttIf9c= -golang.org/x/exp v0.0.0-20200908183739-ae8ad444f925/go.mod h1:1phAWC201xIgDyaFpmDeZkgf70Q4Pd/CNqfRtVPtxNw= -golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= -golang.org/x/image v0.0.0-20190802002840-cff245a6509b h1:+qEpEAPhDZ1o0x3tHzZTQDArnOixOzGD9HUJfcg0mb4= -golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028 h1:4+4C/Iv2U4fMZBiMCc98MG1In4gJY5YRhtpDNeDeHWs= -golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20180921000356-2f5d2388922f/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20181019160139-8e24a49d80f8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24 h1:R8bzl0244nw47n1xKs1MUMAaTNgjavKcN/aX2Ss3+Fo= -golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/test/assets/parse/ymls/1.yml b/test/assets/parse/ymls/1.yml new file mode 100644 index 00000000..fb43df82 --- /dev/null +++ b/test/assets/parse/ymls/1.yml @@ -0,0 +1,37 @@ +label: App +direction: LTR +nodes: +- name: GCP + type: Group + nodes: + - name: dns + label: DNS + type: gcp.Network.DNS + connectTo: + - load-balancer + + - name: services + label: Service Layer + type: Group + nodes: + - label: "Server 1" + - label: "Server 2" + - label: "Server 3" + connectAllFrom: + - load-balancer + connectAllTo: + - cache + + - name: data + label: Data Layer + nodes: + - name: cache + label: "Cache" + type: gcp.Database.Memorystore + connectTo: db + + - name: db + label: "Database" + type: gcp.Database.Sql + + From 2cc64d60a02eb297cd77c16d61263bd7c114c741 Mon Sep 17 00:00:00 2001 From: Denys Vitali Date: Sun, 27 Sep 2020 11:16:41 +0200 Subject: [PATCH 2/2] test: fix YML syntax --- test/assets/parse/ymls/1.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/assets/parse/ymls/1.yml b/test/assets/parse/ymls/1.yml index fb43df82..8007da31 100644 --- a/test/assets/parse/ymls/1.yml +++ b/test/assets/parse/ymls/1.yml @@ -28,7 +28,8 @@ nodes: - name: cache label: "Cache" type: gcp.Database.Memorystore - connectTo: db + connectTo: + - db - name: db label: "Database"