From 0d705d0efd8901ebf865faabf12a80ff6b1ebb74 Mon Sep 17 00:00:00 2001 From: Mark Newman Date: Fri, 9 Jun 2017 15:40:42 +0100 Subject: [PATCH 01/11] Remove output formatting --- auth.go | 2 +- c_service.go | 60 +++++++++++++++---------------- component.go | 46 ++++++++++++++++++++++++ event.go | 35 ++++++++++++++++++ main.go | 95 +++++++++++++++++++------------------------------ nats.go | 51 +++++--------------------- notification.go | 2 +- service.go | 40 +++++++++++++++++++++ setup.go | 6 ++-- 9 files changed, 201 insertions(+), 136 deletions(-) create mode 100644 component.go create mode 100644 event.go create mode 100644 service.go diff --git a/auth.go b/auth.go index 48e05e5..c712b87 100644 --- a/auth.go +++ b/auth.go @@ -51,5 +51,5 @@ func authMiddleware(w http.ResponseWriter, r *http.Request) { } // Pass to sse server - s.HTTPHandler(w, r) + ss.HTTPHandler(w, r) } diff --git a/c_service.go b/c_service.go index 3b6d078..052e7e9 100644 --- a/c_service.go +++ b/c_service.go @@ -5,34 +5,34 @@ package main // Service : ... -type Service struct { -} +//type Service struct { +//} -// Handle : ... -func (n *Service) Handle(subject string, lines []Message) []Message { - switch subject { - case "service.create": - lines = append(lines, Message{Body: "Applying your definition", Level: "INFO"}) - case "service.delete": - lines = append(lines, Message{Body: "Starting environment deletion", Level: "INFO"}) - case "service.create.done": - lines = append(lines, Message{Body: "SUCCESS: rules successfully applied", Level: "SUCCESS"}) - lines = append(lines, Message{Body: "error", Level: "ERROR"}) - case "service.create.error": - lines = append(lines, Message{Body: "\nOops! Something went wrong. Please manually fix any errors shown above and re-apply your definition.", Level: "INFO"}) - lines = append(lines, Message{Body: "error", Level: "ERROR"}) - case "service.delete.done": - lines = append(lines, Message{Body: "SUCCESS: your environment has been successfully deleted", Level: "SUCCESS"}) - lines = append(lines, Message{Body: "success", Level: "SUCCESS"}) - case "service.delete.error": - lines = append(lines, Message{Body: "\nOops! Something went wrong. Please manually fix any errors shown above and re-apply your service deletion.", Level: "INFO"}) - lines = append(lines, Message{Body: "error", Level: "ERROR"}) - case "service.import.done": - lines = append(lines, Message{Body: "SUCCESS: service successfully imported", Level: "SUCCESS"}) - lines = append(lines, Message{Body: "error", Level: "ERROR"}) - case "service.import.error": - lines = append(lines, Message{Body: "\nOops! Something went wrong. Please manually fix any errors shown above and re-apply your definition.", Level: "INFO"}) - lines = append(lines, Message{Body: "error", Level: "ERROR"}) - } - return lines -} +// // Handle : ... +// func (n *Service) Handle(subject string, lines []Message) []Message { +// switch subject { +// case "service.create": +// lines = append(lines, Message{Body: "Applying your definition", Level: "INFO"}) +// case "service.delete": +// lines = append(lines, Message{Body: "Starting environment deletion", Level: "INFO"}) +// case "service.create.done": +// lines = append(lines, Message{Body: "SUCCESS: rules successfully applied", Level: "SUCCESS"}) +// lines = append(lines, Message{Body: "error", Level: "ERROR"}) +// case "service.create.error": +// lines = append(lines, Message{Body: "\nOops! Something went wrong. Please manually fix any errors shown above and re-apply your definition.", Level: "INFO"}) +// lines = append(lines, Message{Body: "error", Level: "ERROR"}) +// case "service.delete.done": +// lines = append(lines, Message{Body: "SUCCESS: your environment has been successfully deleted", Level: "SUCCESS"}) +// lines = append(lines, Message{Body: "success", Level: "SUCCESS"}) +// case "service.delete.error": +// lines = append(lines, Message{Body: "\nOops! Something went wrong. Please manually fix any errors shown above and re-apply your service deletion.", Level: "INFO"}) +// lines = append(lines, Message{Body: "error", Level: "ERROR"}) +// case "service.import.done": +// lines = append(lines, Message{Body: "SUCCESS: service successfully imported", Level: "SUCCESS"}) +// lines = append(lines, Message{Body: "error", Level: "ERROR"}) +// case "service.import.error": +// lines = append(lines, Message{Body: "\nOops! Something went wrong. Please manually fix any errors shown above and re-apply your definition.", Level: "INFO"}) +// lines = append(lines, Message{Body: "error", Level: "ERROR"}) +// } +// return lines +// } diff --git a/component.go b/component.go new file mode 100644 index 0000000..27e00c1 --- /dev/null +++ b/component.go @@ -0,0 +1,46 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package main + +import ( + "encoding/json" + "strings" + + "github.com/nats-io/nats" +) + +type Component struct { + ID string `json:"_component_id"` + Type string `json:"_component"` + State string `json:"_state"` + Action string `json:"_action"` + Provider string `json:"_provider"` + Name string `json:"name"` + Error string `json:"error,omitempty"` + Service string `json:"service,omitempty"` +} + +func componentHandler(msg *nats.Msg) { + var c Component + if err := json.Unmarshal(msg.Data, &c); err != nil { + panic(err) + } + + id := c.getID() + + data, err := json.Marshal(c) + if err != nil { + panic(err) + } + + publishEvent(id, data) +} + +func (c *Component) getID() string { + var pieces []string + pieces = strings.Split(c.Service, "-") + + return pieces[len(pieces)-1] +} diff --git a/event.go b/event.go new file mode 100644 index 0000000..b73a32d --- /dev/null +++ b/event.go @@ -0,0 +1,35 @@ +package main + +import ( + "log" + "time" + + "github.com/r3labs/sse" +) + +func publishEvent(id string, data []byte) { + + // id := svr.getID() + + // data, err := json.Marshal(svr) + // if err != nil { + // panic(err) + // } + + //fmt.Printf("mydata = %+v\n", string(data)) + + // Create a new stream + log.Println("Creating stream for", id) + ss.CreateStream(id) + + ss.Publish(id, data) + + time.Sleep(10 * time.Millisecond) + // Remove a new stream when the build completes + log.Println("Closing stream for", id) + go func(s *sse.Server) { + ss.RemoveStream(id) + }(ss) + + // publishMessage(notification.getServiceID(), &nm) +} diff --git a/main.go b/main.go index 1abe54c..8c922ac 100644 --- a/main.go +++ b/main.go @@ -13,8 +13,8 @@ import ( "github.com/r3labs/sse" ) -var n *nats.Conn -var s *sse.Server +var nc *nats.Conn +var ss *sse.Server var host string var port string var secret string @@ -22,74 +22,51 @@ var err error func main() { setup() - defer n.Close() + defer nc.Close() // Create new SSE server - s = sse.New() - s.AutoStream = true - s.EncodeBase64 = true - defer s.Close() + ss = sse.New() + ss.AutoStream = true + ss.EncodeBase64 = true + defer ss.Close() // Create new HTTP Server and add the route handler mux := http.NewServeMux() mux.HandleFunc("/events", authMiddleware) - // Start nats handler, subscribe to all events related with the monitor - _, err = n.Subscribe("monitor.user", natsHandler) - if err != nil { - log.Println(err) - return + // Subscribe to service events + serviceSubjects := []string{ + "service.create", + "service.delete", + "service.import", } - _, err = n.Subscribe("service.create", natsHandler) - if err != nil { - log.Println(err) - return - } - _, err = n.Subscribe("service.delete", natsHandler) - if err != nil { - log.Println(err) - return - } - _, err = n.Subscribe("service.create.done", natsHandler) - if err != nil { - log.Println(err) - return - } - _, err = n.Subscribe("service.create.error", natsHandler) - if err != nil { - log.Println(err) - return - } - _, err = n.Subscribe("service.delete.done", natsHandler) - if err != nil { - log.Println(err) - return - } - _, err = n.Subscribe("service.delete.error", natsHandler) - if err != nil { - log.Println(err) - return - } - _, err = n.Subscribe("service.import.done", natsHandler) - if err != nil { - log.Println(err) - return - } - _, err = n.Subscribe("service.import.error", natsHandler) - if err != nil { - log.Println(err) - return + + for _, s := range serviceSubjects { + _, err = nc.Subscribe(s, serviceHandler) + if err != nil { + log.Println(err) + return + } } - _, err = n.Subscribe("*.*.*", genericHandler) - if err != nil { - log.Println(err) - return + // Subscribe to component events + componentSubjects := []string{ + "*.create.*", + "*.create.*.*", + "*.update.*", + "*.update.*.*", + "*.delete.*", + "*.delete.*.*", + "*.find.*", + "*.find.*.*", } - _, err = n.Subscribe("*.*.*.*", genericHandler) - if err != nil { - log.Println(err) - return + + for _, s := range componentSubjects { + _, err = nc.Subscribe(s, componentHandler) + if err != nil { + log.Println(err) + return + } } // Start Listening diff --git a/nats.go b/nats.go index fc58b98..a1f7c82 100644 --- a/nats.go +++ b/nats.go @@ -4,45 +4,12 @@ package main -import ( - "github.com/nats-io/nats" - "github.com/r3labs/sse" - "log" - "time" -) - -func natsHandler(msg *nats.Msg) { - var notification Notification - if err := processNotification(¬ification, msg); err != nil { - return - } - - switch msg.Subject { - case "monitor.user": - // Publish messages to subscribers - for _, nm := range notification.Messages { - publishMessage(notification.getServiceID(), &nm) - } - case "service.create", "service.delete": - var handler Service - // Create a new stream - log.Println("Creating stream for", notification.getServiceID()) - s.CreateStream(notification.getServiceID()) - lines := handler.Handle(msg.Subject, notification.Messages) - for _, nm := range lines { - publishMessage(notification.getServiceID(), &nm) - } - case "service.create.done", "service.create.error", "service.delete.done", "service.delete.error", "service.import.done", "service.import.error": - var handler Service - lines := handler.Handle(msg.Subject, notification.Messages) - for _, nm := range lines { - publishMessage(notification.getServiceID(), &nm) - } - time.Sleep(10 * time.Millisecond) - // Remove a new stream when the build completes - log.Println("Closing stream for", notification.getServiceID()) - go func(s *sse.Server) { - s.RemoveStream(notification.getServiceID()) - }(s) - } -} +// func natsHandler(msg *nats.Msg) { +// if strings.HasPrefix(msg.Subject, "service.") { +// fmt.Println("hit service") +// processService(msg) +// } else { +// fmt.Println("hit component") +// processComponent(msg) +// } +// } diff --git a/notification.go b/notification.go index b544df0..1969b04 100644 --- a/notification.go +++ b/notification.go @@ -22,7 +22,7 @@ type Message struct { Level string `json:"level"` } -// Notification stores any user output sent from the FSM +// Notification stores any user output sent from the Scheduler type Notification struct { ID string `json:"id"` Service string `json:"service"` diff --git a/service.go b/service.go new file mode 100644 index 0000000..777a969 --- /dev/null +++ b/service.go @@ -0,0 +1,40 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package main + +import ( + "encoding/json" + "strings" + + "github.com/nats-io/nats" +) + +type Service struct { + ID string `json:"id"` + Changes []Component `json:"changes"` +} + +func serviceHandler(msg *nats.Msg) { + var s Service + if err := json.Unmarshal(msg.Data, &s); err != nil { + panic(err) + } + + id := s.getID() + + data, err := json.Marshal(s) + if err != nil { + panic(err) + } + + publishEvent(id, data) +} + +func (s *Service) getID() string { + var pieces []string + pieces = strings.Split(s.ID, "-") + + return pieces[len(pieces)-1] +} diff --git a/setup.go b/setup.go index d9bef62..6ee46f0 100644 --- a/setup.go +++ b/setup.go @@ -21,7 +21,7 @@ type monitorConfig struct { func setup() { var err error // Open Nats connection - n, err = nats.Connect(os.Getenv("NATS_URI")) + nc, err = nats.Connect(os.Getenv("NATS_URI")) if err != nil { log.Println("Could not connect to nats") return @@ -29,7 +29,7 @@ func setup() { secret = os.Getenv("JWT_SECRET") if secret == "" { - token, err := n.Request("config.get.jwt_token", []byte(""), 1*time.Second) + token, err := nc.Request("config.get.jwt_token", []byte(""), 1*time.Second) if err != nil { panic("Can't get jwt_config config") } @@ -38,7 +38,7 @@ func setup() { } cfg := monitorConfig{} - msg, err := n.Request("config.get.monitor", []byte(""), 1*time.Second) + msg, err := nc.Request("config.get.monitor", []byte(""), 1*time.Second) if err != nil { panic("Can't get monitor config") } From 0204d357ef1a4d9852b3976ad42e26113766192d Mon Sep 17 00:00:00 2001 From: Mark Newman Date: Fri, 9 Jun 2017 19:04:10 +0100 Subject: [PATCH 02/11] Remove component output formatting --- Makefile | 1 + c_ebs_volume.go | 56 --------- c_elb.go | 62 ---------- c_firewall.go | 54 -------- c_instance.go | 64 ---------- c_internet_gateway.go | 56 --------- c_loadbalancer.go | 58 --------- c_loadbalancer_backend_address_pool.go | 58 --------- c_loadbalancer_probe.go | 58 --------- c_loadbalancer_rule.go | 58 --------- c_local_network_gateway.go | 58 --------- c_nat.go | 54 -------- c_network.go | 58 --------- c_network_interface.go | 60 --------- c_network_security_group.go | 58 --------- c_public_ip.go | 58 --------- c_rds_cluster.go | 55 --------- c_rds_instance.go | 58 --------- c_resource_group.go | 56 --------- c_router.go | 48 -------- c_s3.go | 59 --------- c_service.go | 38 ------ c_sql_database.go | 58 --------- c_sql_firewall_rules.go | 58 --------- c_sql_server.go | 58 --------- c_storage_account.go | 58 --------- c_storage_container.go | 58 --------- c_subnet.go | 58 --------- c_virtual_machine.go | 58 --------- c_virtual_network.go | 65 ---------- c_vpc.go | 56 --------- component.go | 2 +- event.go | 34 +----- generic.go | 163 ------------------------- main.go | 38 +----- nats.go | 43 +++++-- notification.go | 57 --------- service.go | 22 +++- 38 files changed, 65 insertions(+), 2006 deletions(-) delete mode 100644 c_ebs_volume.go delete mode 100644 c_elb.go delete mode 100644 c_firewall.go delete mode 100644 c_instance.go delete mode 100644 c_internet_gateway.go delete mode 100644 c_loadbalancer.go delete mode 100644 c_loadbalancer_backend_address_pool.go delete mode 100644 c_loadbalancer_probe.go delete mode 100644 c_loadbalancer_rule.go delete mode 100644 c_local_network_gateway.go delete mode 100644 c_nat.go delete mode 100644 c_network.go delete mode 100644 c_network_interface.go delete mode 100644 c_network_security_group.go delete mode 100644 c_public_ip.go delete mode 100644 c_rds_cluster.go delete mode 100644 c_rds_instance.go delete mode 100644 c_resource_group.go delete mode 100644 c_router.go delete mode 100644 c_s3.go delete mode 100644 c_service.go delete mode 100644 c_sql_database.go delete mode 100644 c_sql_firewall_rules.go delete mode 100644 c_sql_server.go delete mode 100644 c_storage_account.go delete mode 100644 c_storage_container.go delete mode 100644 c_subnet.go delete mode 100644 c_virtual_machine.go delete mode 100644 c_virtual_network.go delete mode 100644 c_vpc.go delete mode 100644 generic.go delete mode 100644 notification.go diff --git a/Makefile b/Makefile index 80f37a8..48201f7 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ deps: go get gopkg.in/redis.v3 go get github.com/nats-io/nats go get github.com/dgrijalva/jwt-go + go get github.com/r3labs/pattern dev-deps: deps go get github.com/smartystreets/goconvey/convey diff --git a/c_ebs_volume.go b/c_ebs_volume.go deleted file mode 100644 index 48a9e37..0000000 --- a/c_ebs_volume.go +++ /dev/null @@ -1,56 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// EBSVolume : ... -type EBSVolume struct { -} - -// Handle : ... -func (n *EBSVolume) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "ebs_volume.create": - lines = n.getSingleDetail(c, "Created EBS volume ") - case "ebs_volume.delete": - lines = n.getSingleDetail(c, "Deleted EBS volume ") - case "ebs_volumes.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found EBS volume")...) - } - } - return lines -} - -func (n *EBSVolume) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - id, _ := c["volume_aws_id"].(string) - if id != "" { - lines = append(lines, Message{Body: " AWS ID : " + id, Level: ""}) - } - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_elb.go b/c_elb.go deleted file mode 100644 index 95e6d24..0000000 --- a/c_elb.go +++ /dev/null @@ -1,62 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// ELB : ... -type ELB struct { -} - -// Handle : ... -func (n *ELB) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "elb.create": - lines = n.getSingleDetail(c, "Created ELB") - case "elb.update": - lines = n.getSingleDetail(c, "Updated ELB") - case "elb.delete": - lines = n.getSingleDetail(c, "Deleted ELB") - case "elbs.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found ELB")...) - } - } - return lines -} - -func (n *ELB) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if c["dns_name"] != nil { - dnsName, _ := c["dns_name"].(string) - if dnsName != "" { - lines = append(lines, Message{Body: " DNS : " + dnsName, Level: ""}) - } - } - lines = append(lines) - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - - return lines -} diff --git a/c_firewall.go b/c_firewall.go deleted file mode 100644 index 56a1518..0000000 --- a/c_firewall.go +++ /dev/null @@ -1,54 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// Firewall : ... -type Firewall struct { -} - -// Handle : ... -func (n *Firewall) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "firewall.create": - lines = n.getSingleDetail(c, "Created Firewall") - case "firewall.update": - lines = n.getSingleDetail(c, "Updated Firewall") - case "firewall.delete": - lines = n.getSingleDetail(c, "Deleted Firewall") - case "firewalls.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found Firewall")...) - } - } - return lines -} - -func (n *Firewall) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_instance.go b/c_instance.go deleted file mode 100644 index eb855e3..0000000 --- a/c_instance.go +++ /dev/null @@ -1,64 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// Instance : ... -type Instance struct { -} - -// Handle : ... -func (n *Instance) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "instance.create": - lines = n.getSingleDetail(c, "Created Instance") - case "instance.update": - lines = n.getSingleDetail(c, "Updated Instance") - case "instance.delete": - lines = n.getSingleDetail(c, "Deleted Instance") - case "instances.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found Instance")...) - } - } - return lines -} - -func (n *Instance) getSingleDetail(c component, prefix string) (lines []Message) { - ip, _ := c["ip"].(string) - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - lines = append(lines, Message{Body: " IP : " + ip, Level: ""}) - publicIP, _ := c["public_ip"].(string) - if publicIP != "" { - lines = append(lines, Message{Body: " PUBLIC IP : " + publicIP, Level: ""}) - } - id, _ := c["instance_aws_id"].(string) - if id != "" { - lines = append(lines, Message{Body: " AWS ID : " + id, Level: ""}) - } - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_internet_gateway.go b/c_internet_gateway.go deleted file mode 100644 index d8bf615..0000000 --- a/c_internet_gateway.go +++ /dev/null @@ -1,56 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// InternetGateway : ... -type InternetGateway struct { -} - -// Handle : ... -func (n *InternetGateway) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "internet_gateway.create": - lines = n.getSingleDetail(c, "Created Internet Gateway") - case "internet_gateway.delete": - lines = n.getSingleDetail(c, "Deleted Internet Gateway") - case "internet_gateways.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found Internet Gateway")...) - } - } - return lines -} - -func (n *InternetGateway) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - id, _ := c["internet_gateway_aws_id"].(string) - if id != "" { - lines = append(lines, Message{Body: " AWS ID : " + id, Level: ""}) - } - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_loadbalancer.go b/c_loadbalancer.go deleted file mode 100644 index e9b3cfa..0000000 --- a/c_loadbalancer.go +++ /dev/null @@ -1,58 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// Lb : ... -type Lb struct { -} - -// Handle : ... -func (n *Lb) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "lb.create": - lines = n.getSingleDetail(c, "Created Loadbalancer") - case "lb.update": - lines = n.getSingleDetail(c, "Updated Loadbalancer") - case "lb.delete": - lines = n.getSingleDetail(c, "Deleted Loadbalancer") - case "lbs.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found Loadbalancer")...) - } - } - return lines -} - -func (n *Lb) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - id, _ := c["id"].(string) - if id != "" { - lines = append(lines, Message{Body: " ID : " + id, Level: ""}) - } - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_loadbalancer_backend_address_pool.go b/c_loadbalancer_backend_address_pool.go deleted file mode 100644 index 821c9c4..0000000 --- a/c_loadbalancer_backend_address_pool.go +++ /dev/null @@ -1,58 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// LbBackendAddressPool : ... -type LbBackendAddressPool struct { -} - -// Handle : ... -func (n *LbBackendAddressPool) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "lb_backend_address_pool.create": - lines = n.getSingleDetail(c, "Created Loadbalancer") - case "lb_backend_address_pool.update": - lines = n.getSingleDetail(c, "Updated Loadbalancer") - case "lb_backend_address_pool.delete": - lines = n.getSingleDetail(c, "Deleted Loadbalancer") - case "lb_backend_address_pools.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found Loadbalancer backend address pool")...) - } - } - return lines -} - -func (n *LbBackendAddressPool) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - id, _ := c["id"].(string) - if id != "" { - lines = append(lines, Message{Body: " ID : " + id, Level: ""}) - } - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_loadbalancer_probe.go b/c_loadbalancer_probe.go deleted file mode 100644 index 2ad9541..0000000 --- a/c_loadbalancer_probe.go +++ /dev/null @@ -1,58 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// LbProbe : ... -type LbProbe struct { -} - -// Handle : ... -func (n *LbProbe) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "lb_probe.create": - lines = n.getSingleDetail(c, "Created Loadbalancer") - case "lb_probe.update": - lines = n.getSingleDetail(c, "Updated Loadbalancer") - case "lb_probe.delete": - lines = n.getSingleDetail(c, "Deleted Loadbalancer") - case "lb_probes.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found Loadbalancer probe")...) - } - } - return lines -} - -func (n *LbProbe) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - id, _ := c["id"].(string) - if id != "" { - lines = append(lines, Message{Body: " ID : " + id, Level: ""}) - } - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_loadbalancer_rule.go b/c_loadbalancer_rule.go deleted file mode 100644 index 1c96787..0000000 --- a/c_loadbalancer_rule.go +++ /dev/null @@ -1,58 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// LbRule : ... -type LbRule struct { -} - -// Handle : ... -func (n *LbRule) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "lb_rule.create": - lines = n.getSingleDetail(c, "Created Loadbalancer") - case "lb_rule.update": - lines = n.getSingleDetail(c, "Updated Loadbalancer") - case "lb_rule.delete": - lines = n.getSingleDetail(c, "Deleted Loadbalancer") - case "lb_rules.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found Loadbalancer Rule")...) - } - } - return lines -} - -func (n *LbRule) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - id, _ := c["id"].(string) - if id != "" { - lines = append(lines, Message{Body: " ID : " + id, Level: ""}) - } - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_local_network_gateway.go b/c_local_network_gateway.go deleted file mode 100644 index 3fe8cb8..0000000 --- a/c_local_network_gateway.go +++ /dev/null @@ -1,58 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// LocalNetworkGateway : ... -type LocalNetworkGateway struct { -} - -// Handle : ... -func (n *LocalNetworkGateway) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "local_network_gateway.create": - lines = n.getSingleDetail(c, "Created Local Network Gateway") - case "local_network_gateway.update": - lines = n.getSingleDetail(c, "Updated Local Network Gateway") - case "local_network_gateway.delete": - lines = n.getSingleDetail(c, "Deleted Local Network Gateway") - case "local_network_gateways.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found Local Network Gateway")...) - } - } - return lines -} - -func (n *LocalNetworkGateway) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - id, _ := c["id"].(string) - if id != "" { - lines = append(lines, Message{Body: " ID : " + id, Level: ""}) - } - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_nat.go b/c_nat.go deleted file mode 100644 index 5568d2b..0000000 --- a/c_nat.go +++ /dev/null @@ -1,54 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// Nat : ... -type Nat struct { -} - -// Handle : ... -func (n *Nat) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "nat.create": - lines = n.getSingleDetail(c, "Created Nat") - case "nat.update": - lines = n.getSingleDetail(c, "Updated Nat") - case "nat.delete": - lines = n.getSingleDetail(c, "Deleted Nat") - case "nats.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found Nat")...) - } - } - return lines -} - -func (n *Nat) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_network.go b/c_network.go deleted file mode 100644 index 3097280..0000000 --- a/c_network.go +++ /dev/null @@ -1,58 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// Network : ... -type Network struct { -} - -// Handle : ... -func (n *Network) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "network.create": - lines = n.getSingleDetail(c, "Created Network") - case "network.delete": - lines = n.getSingleDetail(c, "Deleted Network") - case "networks.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found Network")...) - } - } - return lines -} - -func (n *Network) getSingleDetail(c component, prefix string) (lines []Message) { - ip, _ := c["range"].(string) - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - lines = append(lines, Message{Body: " Subnet : " + ip, Level: ""}) - id, _ := c["network_aws_id"].(string) - if id != "" { - lines = append(lines, Message{Body: " AWS ID : " + id, Level: ""}) - } - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_network_interface.go b/c_network_interface.go deleted file mode 100644 index 111f2d6..0000000 --- a/c_network_interface.go +++ /dev/null @@ -1,60 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import ( - "strings" -) - -// NetworkInterface : ... -type NetworkInterface struct { -} - -// Handle : ... -func (n *NetworkInterface) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "network_interface.create": - lines = n.getSingleDetail(c, "Created Network Interface") - case "network_interface.delete": - lines = n.getSingleDetail(c, "Deleted Network Interface") - case "network_interfaces.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found Network Interface")...) - } - } - return lines -} - -func (n *NetworkInterface) getSingleDetail(c component, prefix string) (lines []Message) { - ip, _ := c["private_ip_address"].(string) - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - lines = append(lines, Message{Body: " IP : " + ip, Level: ""}) - id, _ := c["id"].(string) - if id != "" { - lines = append(lines, Message{Body: " ID : " + id, Level: ""}) - } - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_network_security_group.go b/c_network_security_group.go deleted file mode 100644 index 349677d..0000000 --- a/c_network_security_group.go +++ /dev/null @@ -1,58 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// NetworkSecurityGroup : ... -type NetworkSecurityGroup struct { -} - -// Handle : ... -func (n *NetworkSecurityGroup) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "security_group.create": - lines = n.getSingleDetail(c, "Created Network Security Group") - case "security_group.update": - lines = n.getSingleDetail(c, "Updated Network Security Group") - case "security_group.delete": - lines = n.getSingleDetail(c, "Deleted Network Security Group") - case "security_groups.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found Network Security Group")...) - } - } - return lines -} - -func (n *NetworkSecurityGroup) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - id, _ := c["id"].(string) - if id != "" { - lines = append(lines, Message{Body: " ID : " + id, Level: ""}) - } - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_public_ip.go b/c_public_ip.go deleted file mode 100644 index d8f0023..0000000 --- a/c_public_ip.go +++ /dev/null @@ -1,58 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// PublicIP : ... -type PublicIP struct { -} - -// Handle : ... -func (n *PublicIP) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "public_ip.create": - lines = n.getSingleDetail(c, "Created Public IP") - case "public_ip.delete": - lines = n.getSingleDetail(c, "Deleted Public IP") - case "public_ips.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found Public IP")...) - } - } - return lines -} - -func (n *PublicIP) getSingleDetail(c component, prefix string) (lines []Message) { - ip, _ := c["ip_address"].(string) - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - lines = append(lines, Message{Body: " IP : " + ip, Level: ""}) - id, _ := c["id"].(string) - if id != "" { - lines = append(lines, Message{Body: " ID : " + id, Level: ""}) - } - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_rds_cluster.go b/c_rds_cluster.go deleted file mode 100644 index 133e920..0000000 --- a/c_rds_cluster.go +++ /dev/null @@ -1,55 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// RDSCluster : ... -type RDSCluster struct { -} - -// Handle : ... -func (n *RDSCluster) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "rds_cluster.create": - lines = n.getSingleDetail(c, "Created RDS Cluster") - case "rds_cluster.update": - lines = n.getSingleDetail(c, "Updated RDS Cluster") - case "rds_cluster.delete": - lines = n.getSingleDetail(c, "Deleted RDS Cluster") - case "rds_clusters.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found RDS Cluster")...) - } - } - return lines -} - -func (n *RDSCluster) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - engine, _ := c["engine"].(string) - endpoint, _ := c["endpoint"].(string) - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - lines = append(lines, Message{Body: " Engine : " + engine, Level: ""}) - lines = append(lines, Message{Body: " Endpoint : " + endpoint, Level: ""}) - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_rds_instance.go b/c_rds_instance.go deleted file mode 100644 index 7c0c5b5..0000000 --- a/c_rds_instance.go +++ /dev/null @@ -1,58 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// RDSInstance : ... -type RDSInstance struct { -} - -// Handle : ... -func (n *RDSInstance) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "rds_instance.create": - lines = n.getSingleDetail(c, "Created RDS Instance") - case "rds_instance.udpate": - lines = n.getSingleDetail(c, "Updated RDS Instance") - case "rds_instance.delete": - lines = n.getSingleDetail(c, "Deleted RDS Instance") - case "rds_instances.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found RDS Instance")...) - } - } - return lines -} - -func (n *RDSInstance) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - engine, _ := c["engine"].(string) - cluster, _ := c["cluster"].(string) - endpoint, _ := c["endpoint"].(string) - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - lines = append(lines, Message{Body: " Engine : " + engine, Level: ""}) - lines = append(lines, Message{Body: " Cluster : " + cluster, Level: ""}) - lines = append(lines, Message{Body: " Endpoint : " + endpoint, Level: ""}) - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - - return lines -} diff --git a/c_resource_group.go b/c_resource_group.go deleted file mode 100644 index b02c6b7..0000000 --- a/c_resource_group.go +++ /dev/null @@ -1,56 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// ResourceGroup : ... -type ResourceGroup struct { -} - -// Handle : ... -func (n *ResourceGroup) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "resource_group.create": - lines = n.getSingleDetail(c, "Created Resource Group") - case "resource_group.delete": - lines = n.getSingleDetail(c, "Deleted Resource Group") - case "resource_groups.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found Resource Group")...) - } - } - return lines -} - -func (n *ResourceGroup) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - id, _ := c["id"].(string) - if id != "" { - lines = append(lines, Message{Body: " ID : " + id, Level: ""}) - } - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_router.go b/c_router.go deleted file mode 100644 index e359f96..0000000 --- a/c_router.go +++ /dev/null @@ -1,48 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// Router : ... -type Router struct { -} - -// Handle : ... -func (n *Router) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - - case "router.create", "router.update": - lines = n.getSingleDetail(c, "Configured Router") - } - return lines -} - -func (n *Router) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - - return lines -} diff --git a/c_s3.go b/c_s3.go deleted file mode 100644 index 4f1f6d7..0000000 --- a/c_s3.go +++ /dev/null @@ -1,59 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// S3Bucket : ... -type S3Bucket struct { -} - -// Handle : ... -func (n *S3Bucket) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "s3.create": - lines = n.getSingleDetail(c, "Created S3 Bucket") - case "s3.update": - lines = n.getSingleDetail(c, "Updated S3 Bucket") - case "s3.delete": - lines = n.getSingleDetail(c, "Deleted S3 Bucket") - case "s3s.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found S3 Bucket")...) - } - } - return lines -} - -func (n *S3Bucket) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - acl, _ := c["acl"].(string) - if acl == "" { - acl = "by grantees" - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - lines = append(lines, Message{Body: " ACL : " + acl, Level: ""}) - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_service.go b/c_service.go deleted file mode 100644 index 052e7e9..0000000 --- a/c_service.go +++ /dev/null @@ -1,38 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -// Service : ... -//type Service struct { -//} - -// // Handle : ... -// func (n *Service) Handle(subject string, lines []Message) []Message { -// switch subject { -// case "service.create": -// lines = append(lines, Message{Body: "Applying your definition", Level: "INFO"}) -// case "service.delete": -// lines = append(lines, Message{Body: "Starting environment deletion", Level: "INFO"}) -// case "service.create.done": -// lines = append(lines, Message{Body: "SUCCESS: rules successfully applied", Level: "SUCCESS"}) -// lines = append(lines, Message{Body: "error", Level: "ERROR"}) -// case "service.create.error": -// lines = append(lines, Message{Body: "\nOops! Something went wrong. Please manually fix any errors shown above and re-apply your definition.", Level: "INFO"}) -// lines = append(lines, Message{Body: "error", Level: "ERROR"}) -// case "service.delete.done": -// lines = append(lines, Message{Body: "SUCCESS: your environment has been successfully deleted", Level: "SUCCESS"}) -// lines = append(lines, Message{Body: "success", Level: "SUCCESS"}) -// case "service.delete.error": -// lines = append(lines, Message{Body: "\nOops! Something went wrong. Please manually fix any errors shown above and re-apply your service deletion.", Level: "INFO"}) -// lines = append(lines, Message{Body: "error", Level: "ERROR"}) -// case "service.import.done": -// lines = append(lines, Message{Body: "SUCCESS: service successfully imported", Level: "SUCCESS"}) -// lines = append(lines, Message{Body: "error", Level: "ERROR"}) -// case "service.import.error": -// lines = append(lines, Message{Body: "\nOops! Something went wrong. Please manually fix any errors shown above and re-apply your definition.", Level: "INFO"}) -// lines = append(lines, Message{Body: "error", Level: "ERROR"}) -// } -// return lines -// } diff --git a/c_sql_database.go b/c_sql_database.go deleted file mode 100644 index e54144a..0000000 --- a/c_sql_database.go +++ /dev/null @@ -1,58 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// SQLDatabase : ... -type SQLDatabase struct { -} - -// Handle : ... -func (n *SQLDatabase) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "sql_database.create": - lines = n.getSingleDetail(c, "Created SQL Database") - case "sql_database.update": - lines = n.getSingleDetail(c, "Updated SQL Database") - case "sql_database.delete": - lines = n.getSingleDetail(c, "Deleted SQL Database") - case "sql_databases.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found SQL Database")...) - } - } - return lines -} - -func (n *SQLDatabase) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - id, _ := c["id"].(string) - if id != "" { - lines = append(lines, Message{Body: " ID : " + id, Level: ""}) - } - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_sql_firewall_rules.go b/c_sql_firewall_rules.go deleted file mode 100644 index b6a95ed..0000000 --- a/c_sql_firewall_rules.go +++ /dev/null @@ -1,58 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// SQLFirewallRule : ... -type SQLFirewallRule struct { -} - -// Handle : ... -func (n *SQLFirewallRule) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "sql_firewall_rule.create": - lines = n.getSingleDetail(c, "Created SQL Firewall Rule") - case "sql_firewall_rule.update": - lines = n.getSingleDetail(c, "Updated SQL Firewall Rule") - case "sql_firewall_rule.delete": - lines = n.getSingleDetail(c, "Deleted SQL Firewall Rule") - case "sql_firewall_rules.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found SQL Firewall Rule")...) - } - } - return lines -} - -func (n *SQLFirewallRule) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - id, _ := c["id"].(string) - if id != "" { - lines = append(lines, Message{Body: " ID : " + id, Level: ""}) - } - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_sql_server.go b/c_sql_server.go deleted file mode 100644 index 343a94c..0000000 --- a/c_sql_server.go +++ /dev/null @@ -1,58 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// SQLServer : ... -type SQLServer struct { -} - -// Handle : ... -func (n *SQLServer) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "sql_server.create": - lines = n.getSingleDetail(c, "Created SQL Server") - case "sql_server.update": - lines = n.getSingleDetail(c, "Updated SQL Server") - case "sql_server.delete": - lines = n.getSingleDetail(c, "Deleted SQL Server") - case "sql_servers.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found SQL Server")...) - } - } - return lines -} - -func (n *SQLServer) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - id, _ := c["id"].(string) - if id != "" { - lines = append(lines, Message{Body: " ID : " + id, Level: ""}) - } - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_storage_account.go b/c_storage_account.go deleted file mode 100644 index 29cc387..0000000 --- a/c_storage_account.go +++ /dev/null @@ -1,58 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// StorageAccount : ... -type StorageAccount struct { -} - -// Handle : ... -func (n *StorageAccount) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "storage_account.create": - lines = n.getSingleDetail(c, "Created Storage Account") - case "storage_account.update": - lines = n.getSingleDetail(c, "Updated Storage Account") - case "storage_account.delete": - lines = n.getSingleDetail(c, "Deleted Storage Account") - case "storage_accounts.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found Storage Account")...) - } - } - return lines -} - -func (n *StorageAccount) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - id, _ := c["id"].(string) - if id != "" { - lines = append(lines, Message{Body: " ID : " + id, Level: ""}) - } - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_storage_container.go b/c_storage_container.go deleted file mode 100644 index 463d540..0000000 --- a/c_storage_container.go +++ /dev/null @@ -1,58 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// StorageContainer : ... -type StorageContainer struct { -} - -// Handle : ... -func (n *StorageContainer) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "storage_container.create": - lines = n.getSingleDetail(c, "Created Storage Container") - case "storage_container.update": - lines = n.getSingleDetail(c, "Updated Storage Container") - case "storage_container.delete": - lines = n.getSingleDetail(c, "Deleted Storage Container") - case "storage_containers.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found Storage Container")...) - } - } - return lines -} - -func (n *StorageContainer) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - id, _ := c["id"].(string) - if id != "" { - lines = append(lines, Message{Body: " ID : " + id, Level: ""}) - } - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_subnet.go b/c_subnet.go deleted file mode 100644 index cdfe037..0000000 --- a/c_subnet.go +++ /dev/null @@ -1,58 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// Subnet : ... -type Subnet struct { -} - -// Handle : ... -func (n *Subnet) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "subnet.create": - lines = n.getSingleDetail(c, "Created Subnet") - case "subnet.delete": - lines = n.getSingleDetail(c, "Deleted Subnet") - case "subnets.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found Subnet")...) - } - } - return lines -} - -func (n *Subnet) getSingleDetail(c component, prefix string) (lines []Message) { - ip, _ := c["address_prefix"].(string) - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - lines = append(lines, Message{Body: " Address Prefix : " + ip, Level: ""}) - id, _ := c["id"].(string) - if id != "" { - lines = append(lines, Message{Body: " ID : " + id, Level: ""}) - } - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_virtual_machine.go b/c_virtual_machine.go deleted file mode 100644 index f506624..0000000 --- a/c_virtual_machine.go +++ /dev/null @@ -1,58 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// VirtualMachine : ... -type VirtualMachine struct { -} - -// Handle : ... -func (n *VirtualMachine) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "virtual_machine.create": - lines = n.getSingleDetail(c, "Created Virtual Machine") - case "virtual_machine.update": - lines = n.getSingleDetail(c, "Updated Virtual Machine") - case "virtual_machine.delete": - lines = n.getSingleDetail(c, "Deleted Virtual Machine") - case "virtual_machines.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found Virtual Machine")...) - } - } - return lines -} - -func (n *VirtualMachine) getSingleDetail(c component, prefix string) (lines []Message) { - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - id, _ := c["id"].(string) - if id != "" { - lines = append(lines, Message{Body: " ID : " + id, Level: ""}) - } - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_virtual_network.go b/c_virtual_network.go deleted file mode 100644 index 7745fd4..0000000 --- a/c_virtual_network.go +++ /dev/null @@ -1,65 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import ( - "strings" -) - -// VirtualNetwork : ... -type VirtualNetwork struct { -} - -// Handle : ... -func (n *VirtualNetwork) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "virtual_network.create": - lines = n.getSingleDetail(c, "Created Virtual Network") - case "virtual_network.delete": - lines = n.getSingleDetail(c, "Deleted Virtual Network") - case "virtual_networks.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found Virtual Network")...) - } - } - return lines -} - -func (n *VirtualNetwork) getSingleDetail(c component, prefix string) (lines []Message) { - addressSpace := c["address_space"].([]interface{}) - var netlist []string - for _, a := range addressSpace { - netlist = append(netlist, a.(string)) - } - networks := strings.Join(netlist, ", ") - name, _ := c["name"].(string) - if prefix != "" { - name = prefix + " " + name - } - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + name, Level: level}) - lines = append(lines, Message{Body: " Address Space : " + networks, Level: ""}) - id, _ := c["id"].(string) - if id != "" { - lines = append(lines, Message{Body: " ID : " + id, Level: ""}) - } - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/c_vpc.go b/c_vpc.go deleted file mode 100644 index c8ccd41..0000000 --- a/c_vpc.go +++ /dev/null @@ -1,56 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import "strings" - -// Vpc : ... -type Vpc struct { -} - -// Handle : ... -func (n *Vpc) Handle(subject string, c component, lines []Message) []Message { - parts := strings.Split(subject, ".") - subject = parts[0] + "." + parts[1] - switch subject { - case "vpc.create": - lines = n.getSingleDetail(c, "Created VPC") - case "vpc.update": - lines = n.getSingleDetail(c, "Updated VPC") - case "vpc.delete": - lines = n.getSingleDetail(c, "Deleted VPC") - case "vpcs.find": - for _, cx := range c.getFoundComponents() { - lines = append(lines, n.getSingleDetail(cx, "Found VPC")...) - } - } - return lines -} - -func (n *Vpc) getSingleDetail(c component, prefix string) (lines []Message) { - id, _ := c["vpc_id"].(string) - if prefix != "" { - id = prefix + " " + id - } - subnet, _ := c["subnet"].(string) - status, _ := c["_state"].(string) - level := "INFO" - if status == "errored" { - level = "ERROR" - } - if status != "errored" && status != "completed" && status != "" { - return lines - } - lines = append(lines, Message{Body: " " + id, Level: level}) - lines = append(lines, Message{Body: " Subnet : " + subnet, Level: ""}) - if status != "" { - lines = append(lines, Message{Body: " Status : " + status, Level: ""}) - } - if status == "errored" { - err, _ := c["error"].(string) - lines = append(lines, Message{Body: " Error : " + err, Level: ""}) - } - return lines -} diff --git a/component.go b/component.go index 27e00c1..1c0bbae 100644 --- a/component.go +++ b/component.go @@ -22,7 +22,7 @@ type Component struct { Service string `json:"service,omitempty"` } -func componentHandler(msg *nats.Msg) { +func processComponent(msg *nats.Msg) { var c Component if err := json.Unmarshal(msg.Data, &c); err != nil { panic(err) diff --git a/event.go b/event.go index b73a32d..3fd9e46 100644 --- a/event.go +++ b/event.go @@ -1,35 +1,9 @@ -package main - -import ( - "log" - "time" +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - "github.com/r3labs/sse" -) +package main func publishEvent(id string, data []byte) { - - // id := svr.getID() - - // data, err := json.Marshal(svr) - // if err != nil { - // panic(err) - // } - - //fmt.Printf("mydata = %+v\n", string(data)) - - // Create a new stream - log.Println("Creating stream for", id) - ss.CreateStream(id) - ss.Publish(id, data) - - time.Sleep(10 * time.Millisecond) - // Remove a new stream when the build completes - log.Println("Closing stream for", id) - go func(s *sse.Server) { - ss.RemoveStream(id) - }(ss) - - // publishMessage(notification.getServiceID(), &nm) } diff --git a/generic.go b/generic.go deleted file mode 100644 index eeecac7..0000000 --- a/generic.go +++ /dev/null @@ -1,163 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import ( - "encoding/json" - "log" - "strings" - - "github.com/nats-io/nats" -) - -type component map[string]interface{} - -func (m *component) getServiceID() string { - id, ok := (*m)["service"].(string) - if ok { - return id - } - return "" -} - -func (m *component) getServicePart() string { - pieces := strings.Split(m.getServiceID(), "-") - return pieces[len(pieces)-1] -} - -func (m *component) getFoundComponents() []component { - var c []component - - components, ok := (*m)["components"].([]interface{}) - if ok { - for _, x := range components { - c = append(c, x.(map[string]interface{})) - } - } - - return c -} - -func genericHandler(msg *nats.Msg) { - var msgLines []Message - var c component - - if err := json.Unmarshal(msg.Data, &c); err != nil { - return - } - - parts := strings.Split(msg.Subject, ".") - component := parts[0] - - switch component { - case "ebs_volumes", "ebs_volume": - var nt EBSVolume - msgLines = nt.Handle(msg.Subject, c, msgLines) - case "instances", "instance": - var nt Instance - msgLines = nt.Handle(msg.Subject, c, msgLines) - case "networks", "network": - var nt Network - msgLines = nt.Handle(msg.Subject, c, msgLines) - case "firewalls", "firewall": - var nt Firewall - msgLines = nt.Handle(msg.Subject, c, msgLines) - case "nats", "nat": - var nt Nat - msgLines = nt.Handle(msg.Subject, c, msgLines) - case "routers", "router": - var nt Router - msgLines = nt.Handle(msg.Subject, c, msgLines) - case "vpcs", "vpc": - var nt Vpc - msgLines = nt.Handle(msg.Subject, c, msgLines) - case "elbs", "elb": - var nt ELB - msgLines = nt.Handle(msg.Subject, c, msgLines) - case "s3s", "s3": - var nt S3Bucket - msgLines = nt.Handle(msg.Subject, c, msgLines) - case "rds_clusters", "rds_cluster": - var nt RDSCluster - msgLines = nt.Handle(msg.Subject, c, msgLines) - case "rds_instances", "rds_instance": - var nt RDSInstance - msgLines = nt.Handle(msg.Subject, c, msgLines) - case "internet_gateway", "internet_gateways": - var nt InternetGateway - msgLines = nt.Handle(msg.Subject, c, msgLines) - case "public_ip", "public_ips": - var h PublicIP - msgLines = h.Handle(msg.Subject, c, msgLines) - case "virtual_network", "virtual_networks": - var h VirtualNetwork - msgLines = h.Handle(msg.Subject, c, msgLines) - case "resource_group", "resource_groups": - var h ResourceGroup - msgLines = h.Handle(msg.Subject, c, msgLines) - case "subnet", "subnets": - var h Subnet - msgLines = h.Handle(msg.Subject, c, msgLines) - case "network_interface", "network_interfaces": - var h NetworkInterface - msgLines = h.Handle(msg.Subject, c, msgLines) - case "storage_account", "storage_accounts": - var h StorageAccount - msgLines = h.Handle(msg.Subject, c, msgLines) - case "storage_container", "storage_containers": - var h StorageContainer - msgLines = h.Handle(msg.Subject, c, msgLines) - case "virtual_machine", "virtual_machines": - var h VirtualMachine - msgLines = h.Handle(msg.Subject, c, msgLines) - case "lb", "lbs": - var h Lb - msgLines = h.Handle(msg.Subject, c, msgLines) - case "lb_rule", "lb_rules": - var h LbRule - msgLines = h.Handle(msg.Subject, c, msgLines) - case "lb_probe", "lb_probes": - var h LbProbe - msgLines = h.Handle(msg.Subject, c, msgLines) - case "lb_backend_address_pool", "lb_backend_address_pools": - var h LbProbe - msgLines = h.Handle(msg.Subject, c, msgLines) - case "sql_server", "sql_servers": - var h SQLServer - msgLines = h.Handle(msg.Subject, c, msgLines) - case "local_network_gateway", "local_network_gateways": - var h LocalNetworkGateway - msgLines = h.Handle(msg.Subject, c, msgLines) - case "security_group", "security_groups": - var h NetworkSecurityGroup - msgLines = h.Handle(msg.Subject, c, msgLines) - case "sql_database", "sql_databases": - var h SQLDatabase - msgLines = h.Handle(msg.Subject, c, msgLines) - case "sql_firewall_rule", "sql_firewall_rules": - var h SQLFirewallRule - msgLines = h.Handle(msg.Subject, c, msgLines) - default: - log.Println("unsupported: " + msg.Subject) - } - for _, v := range msgLines { - publishMessage(c.getServicePart(), &v) - } -} - -func genericErrorMessageHandler(components []interface{}, cType, cAction string) (lines []Message) { - for _, c := range components { - component := c.(map[string]interface{}) - if component["status"].(string) == "errored" { - name := component["name"].(string) - msg := component["error"].(string) - msg = strings.Replace(msg, ":", " -", -1) - line := cType + " " + name + " " + cAction + " failed with: \n" + msg - lines = append(lines, Message{Body: line, Level: "ERROR"}) - } - } - - return lines -} diff --git a/main.go b/main.go index 8c922ac..bdc2fc2 100644 --- a/main.go +++ b/main.go @@ -34,39 +34,11 @@ func main() { mux := http.NewServeMux() mux.HandleFunc("/events", authMiddleware) - // Subscribe to service events - serviceSubjects := []string{ - "service.create", - "service.delete", - "service.import", - } - - for _, s := range serviceSubjects { - _, err = nc.Subscribe(s, serviceHandler) - if err != nil { - log.Println(err) - return - } - } - - // Subscribe to component events - componentSubjects := []string{ - "*.create.*", - "*.create.*.*", - "*.update.*", - "*.update.*.*", - "*.delete.*", - "*.delete.*.*", - "*.find.*", - "*.find.*.*", - } - - for _, s := range componentSubjects { - _, err = nc.Subscribe(s, componentHandler) - if err != nil { - log.Println(err) - return - } + // Subscribe to subjects + _, err = nc.Subscribe(">", natsHandler) + if err != nil { + log.Println(err) + return } // Start Listening diff --git a/nats.go b/nats.go index a1f7c82..c3fa46f 100644 --- a/nats.go +++ b/nats.go @@ -4,12 +4,37 @@ package main -// func natsHandler(msg *nats.Msg) { -// if strings.HasPrefix(msg.Subject, "service.") { -// fmt.Println("hit service") -// processService(msg) -// } else { -// fmt.Println("hit component") -// processComponent(msg) -// } -// } +import ( + "github.com/nats-io/nats" + "github.com/r3labs/pattern" +) + +func natsHandler(msg *nats.Msg) { + var services = []string{ + "service.create", + "service.create.*", + "service.delete", + "service.delete.*", + "service.import", + "service.import.*", + } + var components = []string{ + "*.create.*", + "*.create.*.*", + "*.update.*", + "*.update.*.*", + "*.delete.*", + "*.delete.*.*", + "*.find.*", + "*.find.*.*", + } + + switch { + case pattern.Match(msg.Subject, services...): + processService(msg) + case pattern.Match(msg.Subject, components...): + processComponent(msg) + default: + return + } +} diff --git a/notification.go b/notification.go deleted file mode 100644 index 1969b04..0000000 --- a/notification.go +++ /dev/null @@ -1,57 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -import ( - "encoding/json" - "log" - "strings" - - "github.com/nats-io/nats" - "github.com/r3labs/sse" -) - -// Messages holds a collection of the type Message -type Messages []Message - -// Message stores the data of a notification -type Message struct { - Body string `json:"body"` - Level string `json:"level"` -} - -// Notification stores any user output sent from the Scheduler -type Notification struct { - ID string `json:"id"` - Service string `json:"service"` - Messages Messages `json:"messages"` -} - -func (n *Notification) getServiceID() string { - var pieces []string - - if n.Service != "" { - pieces = strings.Split(n.Service, "-") - } else { - pieces = strings.Split(n.ID, "-") - } - - return pieces[len(pieces)-1] -} - -func processNotification(notification *Notification, msg *nats.Msg) error { - return json.Unmarshal(msg.Data, ¬ification) -} - -func publishMessage(service string, msg *Message) { - data, err := json.Marshal(msg) - - if err != nil { - log.Println("Could not encode message: ") - log.Println(err) - } else { - s.Publish(service, &sse.Event{Data: data}) - } -} diff --git a/service.go b/service.go index 777a969..d322f30 100644 --- a/service.go +++ b/service.go @@ -6,9 +6,12 @@ package main import ( "encoding/json" + "log" "strings" + "time" "github.com/nats-io/nats" + "github.com/r3labs/sse" ) type Service struct { @@ -16,7 +19,7 @@ type Service struct { Changes []Component `json:"changes"` } -func serviceHandler(msg *nats.Msg) { +func processService(msg *nats.Msg) { var s Service if err := json.Unmarshal(msg.Data, &s); err != nil { panic(err) @@ -29,7 +32,22 @@ func serviceHandler(msg *nats.Msg) { panic(err) } - publishEvent(id, data) + switch msg.Subject { + case "service.create", "service.delete": + // Create new stream + log.Println("Creating stream: ", id) + ss.CreateStream(id) + publishEvent(id, data) + case "service.create.done", "service.create.error", "service.delete.done", "service.delete.error", "service.import.done", "service.import.error": + publishEvent(id, data) + // publishEvent(id, cliHangup) + time.Sleep(10 * time.Millisecond) + // Remove stream when the build completes + log.Println("Closing stream: ", id) + go func(ss *sse.Server) { + ss.RemoveStream(id) + }(ss) + } } func (s *Service) getID() string { From cb9c7844ba84a3cc965128b00527c4b8a322eda0 Mon Sep 17 00:00:00 2001 From: Mark Newman Date: Mon, 12 Jun 2017 19:13:46 +0100 Subject: [PATCH 03/11] Add _subject attribute to event message --- component.go | 4 ++++ service.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/component.go b/component.go index 1c0bbae..8c616db 100644 --- a/component.go +++ b/component.go @@ -13,6 +13,7 @@ import ( type Component struct { ID string `json:"_component_id"` + Subject string `json:"_subject"` Type string `json:"_component"` State string `json:"_state"` Action string `json:"_action"` @@ -24,6 +25,9 @@ type Component struct { func processComponent(msg *nats.Msg) { var c Component + + c.Subject = msg.Subject + if err := json.Unmarshal(msg.Data, &c); err != nil { panic(err) } diff --git a/service.go b/service.go index d322f30..510c22c 100644 --- a/service.go +++ b/service.go @@ -16,11 +16,15 @@ import ( type Service struct { ID string `json:"id"` + Subject string `json:"_subject"` Changes []Component `json:"changes"` } func processService(msg *nats.Msg) { var s Service + + s.Subject = msg.Subject + if err := json.Unmarshal(msg.Data, &s); err != nil { panic(err) } @@ -41,6 +45,7 @@ func processService(msg *nats.Msg) { case "service.create.done", "service.create.error", "service.delete.done", "service.delete.error", "service.import.done", "service.import.error": publishEvent(id, data) // publishEvent(id, cliHangup) + time.Sleep(10 * time.Millisecond) // Remove stream when the build completes log.Println("Closing stream: ", id) From 0dbb594276e2f8c8dd4802301047f65883412181 Mon Sep 17 00:00:00 2001 From: Mark Newman Date: Fri, 16 Jun 2017 18:11:29 +0100 Subject: [PATCH 04/11] Clean up error handling --- component.go | 9 ++++++--- event.go | 9 --------- service.go | 12 ++++++------ 3 files changed, 12 insertions(+), 18 deletions(-) delete mode 100644 event.go diff --git a/component.go b/component.go index 8c616db..aa5db03 100644 --- a/component.go +++ b/component.go @@ -6,6 +6,7 @@ package main import ( "encoding/json" + "log" "strings" "github.com/nats-io/nats" @@ -29,17 +30,19 @@ func processComponent(msg *nats.Msg) { c.Subject = msg.Subject if err := json.Unmarshal(msg.Data, &c); err != nil { - panic(err) + log.Println(err) + return } id := c.getID() data, err := json.Marshal(c) if err != nil { - panic(err) + log.Println(err) + return } - publishEvent(id, data) + ss.Publish(id, data) } func (c *Component) getID() string { diff --git a/event.go b/event.go deleted file mode 100644 index 3fd9e46..0000000 --- a/event.go +++ /dev/null @@ -1,9 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -func publishEvent(id string, data []byte) { - ss.Publish(id, data) -} diff --git a/service.go b/service.go index 510c22c..59512b8 100644 --- a/service.go +++ b/service.go @@ -26,14 +26,16 @@ func processService(msg *nats.Msg) { s.Subject = msg.Subject if err := json.Unmarshal(msg.Data, &s); err != nil { - panic(err) + log.Println(err) + return } id := s.getID() data, err := json.Marshal(s) if err != nil { - panic(err) + log.Println(err) + return } switch msg.Subject { @@ -41,11 +43,9 @@ func processService(msg *nats.Msg) { // Create new stream log.Println("Creating stream: ", id) ss.CreateStream(id) - publishEvent(id, data) + ss.Publish(id, data) case "service.create.done", "service.create.error", "service.delete.done", "service.delete.error", "service.import.done", "service.import.error": - publishEvent(id, data) - // publishEvent(id, cliHangup) - + ss.Publish(id, data) time.Sleep(10 * time.Millisecond) // Remove stream when the build completes log.Println("Closing stream: ", id) From 4febbcc3fb88561abd5267d9492ae96620bb25a1 Mon Sep 17 00:00:00 2001 From: Mark Newman Date: Wed, 21 Jun 2017 15:44:04 +0100 Subject: [PATCH 05/11] Correct missing NATS subject --- service.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/service.go b/service.go index 59512b8..b6e3d31 100644 --- a/service.go +++ b/service.go @@ -39,15 +39,13 @@ func processService(msg *nats.Msg) { } switch msg.Subject { - case "service.create", "service.delete": - // Create new stream + case "service.create", "service.delete", "service.import": log.Println("Creating stream: ", id) ss.CreateStream(id) ss.Publish(id, data) case "service.create.done", "service.create.error", "service.delete.done", "service.delete.error", "service.import.done", "service.import.error": ss.Publish(id, data) time.Sleep(10 * time.Millisecond) - // Remove stream when the build completes log.Println("Closing stream: ", id) go func(ss *sse.Server) { ss.RemoveStream(id) From d90ded2edfdaa16cdfdd702a350b125c834e9920 Mon Sep 17 00:00:00 2001 From: Mark Newman Date: Wed, 5 Jul 2017 16:56:51 +0100 Subject: [PATCH 06/11] Add service name to return object --- service.go | 1 + 1 file changed, 1 insertion(+) diff --git a/service.go b/service.go index b6e3d31..32363e2 100644 --- a/service.go +++ b/service.go @@ -16,6 +16,7 @@ import ( type Service struct { ID string `json:"id"` + Name string `json:"name"` Subject string `json:"_subject"` Changes []Component `json:"changes"` } From 9303cb60fcb21b47af61b7bd98148882c1d8c4e3 Mon Sep 17 00:00:00 2001 From: Tom Bevan Date: Thu, 6 Jul 2017 18:33:12 +0100 Subject: [PATCH 07/11] fixing tests and sse library interface changes --- component.go | 17 +++++++++----- main_test.go | 63 ++++++++++++++++++++++++---------------------------- nats.go | 2 -- service.go | 10 +++++---- setup.go | 4 ++-- 5 files changed, 49 insertions(+), 47 deletions(-) diff --git a/component.go b/component.go index aa5db03..bc96275 100644 --- a/component.go +++ b/component.go @@ -10,8 +10,10 @@ import ( "strings" "github.com/nats-io/nats" + "github.com/r3labs/sse" ) +// Component : holds component values type Component struct { ID string `json:"_component_id"` Subject string `json:"_subject"` @@ -35,19 +37,24 @@ func processComponent(msg *nats.Msg) { } id := c.getID() - data, err := json.Marshal(c) if err != nil { log.Println(err) return } - ss.Publish(id, data) + if ss.StreamExists(id) { + ss.Publish(id, &sse.Event{Data: data}) + } } func (c *Component) getID() string { - var pieces []string - pieces = strings.Split(c.Service, "-") + if strings.Contains(c.Service, "-") { + var pieces []string + pieces = strings.Split(c.Service, "-") + + return pieces[len(pieces)-1] + } - return pieces[len(pieces)-1] + return c.Service } diff --git a/main_test.go b/main_test.go index 5bc0d53..beacfbb 100644 --- a/main_test.go +++ b/main_test.go @@ -33,43 +33,43 @@ func TestMain(t *testing.T) { Convey("Given a new server", t, func() { // New Server - s = sse.New() - defer s.Close() + ss = sse.New() + defer ss.Close() mux := http.NewServeMux() - mux.HandleFunc("/events", s.HTTPHandler) + mux.HandleFunc("/events", ss.HTTPHandler) hs := httptest.NewServer(mux) url := hs.URL + "/events" Convey("When listening for NATS messages", func() { - createEvents := []string{"service.create", "service.delete"} + createEvents := []string{"service.create", "service.delete", "service.import"} for _, event := range createEvents { Convey("On receiving "+event, func() { - msg := nats.Msg{Subject: event, Data: []byte(`{"service": "test"}`)} + msg := nats.Msg{Subject: event, Data: []byte(`{"id": "test"}`)} natsHandler(&msg) time.Sleep(time.Millisecond * 10) Convey("It should create a stream for the service", func() { - So(s.StreamExists("test"), ShouldBeTrue) + So(ss.StreamExists("test"), ShouldBeTrue) }) }) } - deleteEvents := []string{"service.create.done", "service.delete.done", "service.create.error", "service.delete.error"} + deleteEvents := []string{"service.create.done", "service.delete.done", "service.import.done", "service.create.error", "service.delete.error", "service.import.error"} for _, event := range deleteEvents { - s.CreateStream("test") + ss.CreateStream("test") time.Sleep(time.Millisecond * 10) Convey("On receiving "+event, func() { - msg := nats.Msg{Subject: event, Data: []byte(`{"service": "test"}`)} + msg := nats.Msg{Subject: event, Data: []byte(`{"id": "test"}`)} natsHandler(&msg) time.Sleep(time.Millisecond * 1500) Convey("It should remove the services stream", func() { - So(s.StreamExists("test"), ShouldBeFalse) + So(ss.StreamExists("test"), ShouldBeFalse) }) }) @@ -77,26 +77,26 @@ func TestMain(t *testing.T) { Convey("On receiving an unknown message", func() { // Clean server - s.RemoveStream("test") + ss.RemoveStream("test") time.Sleep(time.Millisecond * 10) - msg := nats.Msg{Subject: "test.event", Data: []byte(`{"service": "test"}`)} + msg := nats.Msg{Subject: "test.event", Data: []byte(`{"id": "test"}`)} natsHandler(&msg) Convey("It should not create a stream", func() { - So(s.StreamExists("test"), ShouldBeFalse) + So(ss.StreamExists("test"), ShouldBeFalse) }) }) - Convey("When receiving monitor.user", func() { - testEvent := `{"service": "test", "messages":[{"body": "test", "color": "blue"}]}` - msg := nats.Msg{Subject: "monitor.user", Data: []byte(testEvent)} + Convey("When receiving component event network.create.aws.done", func() { + testEvent := `{"service": "test", "name": "network"}` + msg := nats.Msg{Subject: "network.create.aws.done", Data: []byte(testEvent)} Convey("And a stream exists", func() { rcv := make(chan *sse.Event) cl := sse.NewClient(url) - s.CreateStream("test") + ss.CreateStream("test") time.Sleep(time.Millisecond * 10) go func() { @@ -107,14 +107,19 @@ func TestMain(t *testing.T) { Convey("It should publish a message to the stream", func() { natsHandler(&msg) - event, err := wait(rcv, time.Millisecond*100) + for { + event, err := wait(rcv, time.Millisecond*100) + So(err, ShouldBeNil) - So(err, ShouldBeNil) - So(string(event.Data), ShouldEqual, `{"body":"test","level":""}`) + if len(event.Data) > 0 { + So(string(event.Data), ShouldEqual, `{"_component_id":"","_subject":"network.create.aws.done","_component":"","_state":"","_action":"","_provider":"","name":"network","service":"test"}`) + break + } + } }) }) - s.RemoveStream("test") + ss.RemoveStream("test") Convey("And a stream doesn't exist", func() { rcv := make(chan *sse.Event) @@ -122,19 +127,9 @@ func TestMain(t *testing.T) { time.Sleep(time.Millisecond * 10) - go func() { - _ = cl.SubscribeChan("test", rcv) - }() - time.Sleep(time.Millisecond * 10) - - Convey("It should not publish a message to the stream", func() { - natsHandler(&msg) - event, err := wait(rcv, time.Millisecond*100) - - So(err, ShouldBeNil) - if err != nil { - So(string(event.Data), ShouldNotEqual, `{"body":"test","color":"blue"}`) - } + Convey("It should error when connecting to the stream", func() { + err := cl.SubscribeChan("test", rcv) + So(err, ShouldNotBeNil) }) }) }) diff --git a/nats.go b/nats.go index c3fa46f..1f590c7 100644 --- a/nats.go +++ b/nats.go @@ -34,7 +34,5 @@ func natsHandler(msg *nats.Msg) { processService(msg) case pattern.Match(msg.Subject, components...): processComponent(msg) - default: - return } } diff --git a/service.go b/service.go index 32363e2..336139b 100644 --- a/service.go +++ b/service.go @@ -14,6 +14,7 @@ import ( "github.com/r3labs/sse" ) +// Service : holds service values type Service struct { ID string `json:"id"` Name string `json:"name"` @@ -43,12 +44,13 @@ func processService(msg *nats.Msg) { case "service.create", "service.delete", "service.import": log.Println("Creating stream: ", id) ss.CreateStream(id) - ss.Publish(id, data) + ss.Publish(id, &sse.Event{Data: data}) case "service.create.done", "service.create.error", "service.delete.done", "service.delete.error", "service.import.done", "service.import.error": - ss.Publish(id, data) - time.Sleep(10 * time.Millisecond) - log.Println("Closing stream: ", id) + ss.Publish(id, &sse.Event{Data: data}) go func(ss *sse.Server) { + // Wait for any late connecting clients before closing stream + time.Sleep(1 * time.Second) + log.Println("Closing stream: ", id) ss.RemoveStream(id) }(ss) } diff --git a/setup.go b/setup.go index 6ee46f0..53ff013 100644 --- a/setup.go +++ b/setup.go @@ -29,8 +29,8 @@ func setup() { secret = os.Getenv("JWT_SECRET") if secret == "" { - token, err := nc.Request("config.get.jwt_token", []byte(""), 1*time.Second) - if err != nil { + token, aerr := nc.Request("config.get.jwt_token", []byte(""), 1*time.Second) + if aerr != nil { panic("Can't get jwt_config config") } From 79d639cae9dc58238f5153f661c8af9d6f62cedd Mon Sep 17 00:00:00 2001 From: Mark Newman Date: Fri, 7 Jul 2017 18:23:53 +0100 Subject: [PATCH 08/11] Add components field --- component.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/component.go b/component.go index bc96275..18c14f4 100644 --- a/component.go +++ b/component.go @@ -15,15 +15,16 @@ import ( // Component : holds component values type Component struct { - ID string `json:"_component_id"` - Subject string `json:"_subject"` - Type string `json:"_component"` - State string `json:"_state"` - Action string `json:"_action"` - Provider string `json:"_provider"` - Name string `json:"name"` - Error string `json:"error,omitempty"` - Service string `json:"service,omitempty"` + ID string `json:"_component_id"` + Subject string `json:"_subject"` + Type string `json:"_component"` + State string `json:"_state"` + Action string `json:"_action"` + Provider string `json:"_provider"` + Name string `json:"name"` + Error string `json:"error,omitempty"` + Service string `json:"service,omitempty"` + Components []Component `json:"components,omitempty"` } func processComponent(msg *nats.Msg) { From 48e7a8192cf665ffa780c62d9788110203d42141 Mon Sep 17 00:00:00 2001 From: Mark Newman Date: Mon, 10 Jul 2017 18:41:26 +0100 Subject: [PATCH 09/11] Include dependencies for integration tests --- .ernest-ci | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ernest-ci b/.ernest-ci index 8b13789..66ffb66 100644 --- a/.ernest-ci +++ b/.ernest-ci @@ -1 +1 @@ - +ernest-cli:f-apply-output-529 From e04936a8d4bb5b1344946a00c1c3b3254acee0e8 Mon Sep 17 00:00:00 2001 From: Mark Newman Date: Mon, 10 Jul 2017 18:59:18 +0100 Subject: [PATCH 10/11] Include dependencies for integration tests --- .ernest-ci | 1 + 1 file changed, 1 insertion(+) diff --git a/.ernest-ci b/.ernest-ci index 66ffb66..42f01b7 100644 --- a/.ernest-ci +++ b/.ernest-ci @@ -1 +1,2 @@ +ernest:f-apply-output-529 ernest-cli:f-apply-output-529 From 3b9520432b5ba580a581452e5f4cbc1eb8828e47 Mon Sep 17 00:00:00 2001 From: Tom Bevan Date: Tue, 11 Jul 2017 16:28:44 +0100 Subject: [PATCH 11/11] removed locked branches from ernest-ci file --- .ernest-ci | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.ernest-ci b/.ernest-ci index 42f01b7..8b13789 100644 --- a/.ernest-ci +++ b/.ernest-ci @@ -1,2 +1 @@ -ernest:f-apply-output-529 -ernest-cli:f-apply-output-529 +