-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from ernestio/b-sql-fw-progress-478
Add informational reporting for sql_firewall_rules
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters