Skip to content

Commit

Permalink
Merge pull request #24 from ernestio/refactor
Browse files Browse the repository at this point in the history
Support for single resources
  • Loading branch information
adriacidre authored Mar 2, 2017
2 parents 1dfae1c + e0c4bde commit 425c76b
Show file tree
Hide file tree
Showing 19 changed files with 391 additions and 540 deletions.
4 changes: 4 additions & 0 deletions .linter.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"DisableAll": true,
"Enable": ["golint", "vet", "errcheck"]
}
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ deps: dev-deps

dev-deps:
go get github.com/smartystreets/goconvey/convey
go get github.com/golang/lint/golint
go get github.com/alecthomas/gometalinter
gometalinter --install

cover:
go test -v ./... --cover
Expand All @@ -21,5 +22,5 @@ build:
go build -v ./...

lint:
golint ./...
go vet ./...
gometalinter --config .linter.conf

37 changes: 17 additions & 20 deletions c_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,32 @@

package main

// Bootstrap : ..
type Bootstrap struct {
}

// Handle : ..
func (n *Bootstrap) Handle(subject string, components []interface{}, lines []Message) []Message {
switch subject {
case "bootstraps.create":
lines = append(lines, Message{Body: "Running bootstraps:", Level: "INFO"})
case "bootstraps.create.done":
lines = n.getDetails(components)
return append(lines, Message{Body: "Bootstrap ran", Level: "INFO"})
case "bootstraps.create.error":
lines = n.getDetails(components)
return append(lines, Message{Body: "Bootstrap failed", Level: "INFO"})
case "bootstrap.create.done", "bootstrap.create.error":
lines = n.getSingleDetail(components, "Bootstrap ran")
}

return lines
}

func (n *Bootstrap) getDetails(components []interface{}) (lines []Message) {
for _, v := range components {
r := v.(map[string]interface{})
name, _ := r["name"].(string)
status, _ := r["status"].(string)
lines = append(lines, Message{Body: " - " + name, Level: ""})
lines = append(lines, Message{Body: " Status : " + status, Level: ""})
if status == "errored" {
err, _ := r["error"].(string)
lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"})
}
func (n *Bootstrap) getSingleDetail(v interface{}, prefix string) (lines []Message) {
r := v.(map[string]interface{})
name, _ := r["name"].(string)
if prefix != "" {
name = prefix + " " + name
}
status, _ := r["status"].(string)
lines = append(lines, Message{Body: " - " + name, Level: ""})
lines = append(lines, Message{Body: " Status : " + status, Level: ""})
if status == "errored" {
err, _ := r["error"].(string)
lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"})
}

return lines
}
65 changes: 25 additions & 40 deletions c_ebs_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,39 @@

package main

// EBSVolume : ...
type EBSVolume struct {
}

func (v *EBSVolume) Handle(subject string, components []interface{}, lines []Message) []Message {
// Handle : ...
func (n *EBSVolume) Handle(subject string, components []interface{}, lines []Message) []Message {
switch subject {
case "ebs_volumes.create":
return append(lines, Message{Body: "Creating ebs volumes:", Level: "INFO"})
case "ebs_volumes.create.done":
lines = v.getDetails(components)
return append(lines, Message{Body: "EBS volumes successfully created", Level: "INFO"})
case "ebs_volumes.create.error":
lines = v.getDetails(components)
return append(lines, Message{Body: "EBS volumes creation failed", Level: "INFO"})
case "ebs_volumes.delete":
return append(lines, Message{Body: "Deleting ebs volumes:", Level: "INFO"})
case "ebs_volumes.delete.done":
lines = v.getDetails(components)
return append(lines, Message{Body: "EBS volumes deleted", Level: "INFO"})
case "ebs_volumes.delete.error":
lines = v.getDetails(components)
return append(lines, Message{Body: "EBS volumes deletion failed", Level: "INFO"})
case "ebs_volumes.find":
return append(lines, Message{Body: "Importing ebs volumes:", Level: "INFO"})
case "ebs_volumes.find.done":
lines = v.getDetails(components)
return append(lines, Message{Body: "EBS volumes successfully imported", Level: "INFO"})
case "ebs_volumes.find.error":
lines = v.getDetails(components)
return append(lines, Message{Body: "EBS volumes import failed", Level: "INFO"})
case "ebs_volume.create.done", "ebs_volume.create.error":
lines = n.getSingleDetail(components, "Created EBS volume ")
case "ebs_volume.delete.done", "ebs_volume.delete.error":
lines = n.getSingleDetail(components, "Deleted EBS volume ")
case "ebs_volume.find.done", "ebs_volume.find.error":
lines = n.getSingleDetail(components, "Found EBS volume ")
}
return lines
}

func (v *EBSVolume) getDetails(components []interface{}) (lines []Message) {
for _, v := range components {
r := v.(map[string]interface{})
name, _ := r["name"].(string)
status, _ := r["status"].(string)
lines = append(lines, Message{Body: " - " + name, Level: ""})
id, _ := r["volume_aws_id"].(string)
if id != "" {
lines = append(lines, Message{Body: " AWS ID : " + id, Level: ""})
}
lines = append(lines, Message{Body: " Status : " + status, Level: ""})
if status == "errored" {
err, _ := r["error"].(string)
lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"})
}
func (n *EBSVolume) getSingleDetail(v interface{}, prefix string) (lines []Message) {
r := v.(map[string]interface{})
name, _ := r["name"].(string)
if prefix != "" {
name = prefix + " " + name
}
status, _ := r["status"].(string)
lines = append(lines, Message{Body: " - " + name, Level: ""})
id, _ := r["volume_aws_id"].(string)
if id != "" {
lines = append(lines, Message{Body: " AWS ID : " + id, Level: ""})
}
lines = append(lines, Message{Body: " Status : " + status, Level: ""})
if status == "errored" {
err, _ := r["error"].(string)
lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"})
}
return lines
}
78 changes: 29 additions & 49 deletions c_elb.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,46 @@

package main

// ELB : ...
type ELB struct {
}

// Handle : ...
func (n *ELB) Handle(subject string, components []interface{}, lines []Message) []Message {
switch subject {
case "elbs.create":
lines = append(lines, Message{Body: "Creating ELBs:", Level: "INFO"})
case "elbs.create.done":
lines = n.getDetails(components)
return append(lines, Message{Body: "ELBs created", Level: "INFO"})
case "elbs.create.error":
lines = n.getDetails(components)
return append(lines, Message{Body: "ELBs creation failed", Level: "INFO"})
case "elbs.update":
return append(lines, Message{Body: "Updating ELBs:", Level: "INFO"})
case "elbs.update.done":
lines = n.getDetails(components)
return append(lines, Message{Body: "ELBs updated", Level: "INFO"})
case "elbs.update.error":
lines = n.getDetails(components)
return append(lines, Message{Body: "ELBs modification failed", Level: "INFO"})
case "elbs.delete":
return append(lines, Message{Body: "Deleting ELBs:", Level: "INFO"})
case "elbs.delete.done":
lines = n.getDetails(components)
return append(lines, Message{Body: "ELBs deleted", Level: "INFO"})
case "elbs.delete.error":
lines = n.getDetails(components)
return append(lines, Message{Body: "ELBs deletion failed", Level: "INFO"})
case "elbs.find":
lines = append(lines, Message{Body: "Importing ELBs:", Level: "INFO"})
case "elbs.find.done":
lines = n.getDetails(components)
return append(lines, Message{Body: "ELBs imported", Level: "INFO"})
case "elbs.find.error":
lines = n.getDetails(components)
return append(lines, Message{Body: "ELBs import failed", Level: "INFO"})
case "elb.create.done", "elb.create.error":
lines = n.getSingleDetail(components, "Created ELB")
case "elb.update.done", "elb.update.error":
lines = n.getSingleDetail(components, "Updated ELB")
case "elb.delete.done", "elb.delete.error":
lines = n.getSingleDetail(components, "Deleted ELB")
case "elb.find.done", "elb.find.error":
lines = n.getSingleDetail(components, "Found ELB")

}
return lines
}

func (n *ELB) getDetails(components []interface{}) (lines []Message) {
for _, v := range components {
r := v.(map[string]interface{})
name, _ := r["name"].(string)
status, _ := r["status"].(string)
lines = append(lines, Message{Body: " - " + name, Level: ""})
lines = append(lines, Message{Body: " Status : " + status, Level: ""})
if r["dns_name"] != nil {
dnsName, _ := r["dns_name"].(string)
if dnsName != "" {
lines = append(lines, Message{Body: " DNS : " + dnsName, Level: ""})
}
}
lines = append(lines)
if status == "errored" {
err, _ := r["error"].(string)
lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"})
func (n *ELB) getSingleDetail(v interface{}, prefix string) (lines []Message) {
r := v.(map[string]interface{})
name, _ := r["name"].(string)
if prefix != "" {
name = prefix + " " + name
}
status, _ := r["status"].(string)
lines = append(lines, Message{Body: " - " + name, Level: ""})
lines = append(lines, Message{Body: " Status : " + status, Level: ""})
if r["dns_name"] != nil {
dnsName, _ := r["dns_name"].(string)
if dnsName != "" {
lines = append(lines, Message{Body: " DNS : " + dnsName, Level: ""})
}
}
lines = append(lines)
if status == "errored" {
err, _ := r["error"].(string)
lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"})
}

return lines
}
36 changes: 16 additions & 20 deletions c_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,31 @@

package main

// Execution : ...
type Execution struct {
}

// Handle : ...
func (n *Execution) Handle(subject string, components []interface{}, lines []Message) []Message {
switch subject {
case "executions.create":
lines = append(lines, Message{Body: "Running executions:", Level: "INFO"})
case "executions.create.done":
lines = n.getDetails(components)
return append(lines, Message{Body: "Executions ran", Level: "INFO"})
case "executions.create.error":
lines = n.getDetails(components)
return append(lines, Message{Body: "Executions failed", Level: "INFO"})
case "execution.create.done", "execution.create.error":
lines = n.getSingleDetail(components, "Ran execution")
}
return lines
}

func (n *Execution) getDetails(components []interface{}) (lines []Message) {
for _, v := range components {
r := v.(map[string]interface{})
name, _ := r["name"].(string)
status, _ := r["status"].(string)
lines = append(lines, Message{Body: " - " + name, Level: ""})
lines = append(lines, Message{Body: " Status : " + status, Level: ""})
if status == "errored" {
err, _ := r["error"].(string)
lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"})
}
func (n *Execution) getSingleDetail(v interface{}, prefix string) (lines []Message) {
r := v.(map[string]interface{})
name, _ := r["name"].(string)
if prefix != "" {
name = prefix + " " + name
}
status, _ := r["status"].(string)
lines = append(lines, Message{Body: " - " + name, Level: ""})
lines = append(lines, Message{Body: " Status : " + status, Level: ""})
if status == "errored" {
err, _ := r["error"].(string)
lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"})
}

return lines
}
66 changes: 22 additions & 44 deletions c_firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,37 @@

package main

// Firewall : ...
type Firewall struct {
}

// Handle : ...
func (n *Firewall) Handle(subject string, components []interface{}, lines []Message) []Message {
switch subject {
case "firewalls.create":
lines = append(lines, Message{Body: "Creating firewalls:", Level: "INFO"})
case "firewalls.create.done":
lines = n.getDetails(components)
return append(lines, Message{Body: "Firewalls created", Level: "INFO"})
case "firewalls.create.error":
lines = n.getDetails(components)
return append(lines, Message{Body: "Firewalls creation failed", Level: "INFO"})
case "firewalls.update":
return append(lines, Message{Body: "Updating firewalls:", Level: "INFO"})
case "firewalls.update.done":
lines = n.getDetails(components)
return append(lines, Message{Body: "Firewalls updated", Level: "INFO"})
case "firewalls.update.error":
lines = n.getDetails(components)
return append(lines, Message{Body: "Firewalls modification failed", Level: "INFO"})
case "firewalls.delete":
return append(lines, Message{Body: "Deleting firewalls:", Level: "INFO"})
case "firewalls.delete.done":
lines = n.getDetails(components)
return append(lines, Message{Body: "Firewalls deleted", Level: "INFO"})
case "firewalls.delete.error":
lines = n.getDetails(components)
return append(lines, Message{Body: "Firewalls deletion failed", Level: "INFO"})
case "firewalls.find":
lines = append(lines, Message{Body: "Importing firewalls:", Level: "INFO"})
case "firewalls.find.done":
lines = n.getDetails(components)
return append(lines, Message{Body: "Firewalls imported", Level: "INFO"})
case "firewalls.find.error":
lines = n.getDetails(components)
return append(lines, Message{Body: "Firewalls import failed", Level: "INFO"})
case "firewall.create.done", "firewall.create.error":
lines = n.getSingleDetail(components, "Firewall created")
case "firewall.update.done", "firewall.update.error":
lines = n.getSingleDetail(components, "Firewall updated")
case "firewall.delete.done", "firewall.delete.error":
lines = n.getSingleDetail(components, "Firewall deleted")
case "firewall.find.done", "firewall.find.error":
lines = n.getSingleDetail(components, "Firewall found")
}
return lines
}

func (n *Firewall) getDetails(components []interface{}) (lines []Message) {
for _, v := range components {
r := v.(map[string]interface{})
name, _ := r["name"].(string)
status, _ := r["status"].(string)
lines = append(lines, Message{Body: " - " + name, Level: ""})
lines = append(lines, Message{Body: " Status : " + status, Level: ""})
if status == "errored" {
err, _ := r["error"].(string)
lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"})
}
func (n *Firewall) getSingleDetail(v interface{}, prefix string) (lines []Message) {
r := v.(map[string]interface{})
name, _ := r["name"].(string)
if prefix != "" {
name = prefix + " " + name
}
status, _ := r["status"].(string)
lines = append(lines, Message{Body: " - " + name, Level: ""})
lines = append(lines, Message{Body: " Status : " + status, Level: ""})
if status == "errored" {
err, _ := r["error"].(string)
lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"})
}

return lines
}
Loading

0 comments on commit 425c76b

Please sign in to comment.