Code cleanup.

This commit is contained in:
Filip Barl
2019-02-22 14:56:44 +01:00
parent 2c56ec2bf1
commit c5022bd2bb
5 changed files with 73 additions and 81 deletions
+19 -20
View File
@@ -4,41 +4,40 @@ import (
"github.com/weaveworks/scope/report"
)
func isCommand(key string) bool {
return key == report.Cmdline || key == report.DockerContainerCommand
}
func censorNodeSummary(s *NodeSummary, cfg report.CensorConfig) {
if cfg.HideEnvironmentVariables {
tables := []report.Table{}
for _, t := range s.Tables {
if t.ID != report.DockerEnvPrefix {
tables = append(tables, t)
if cfg.HideCommandLineArguments {
// Iterate through all the metadata rows and strip the
// arguments from all the values containing a command.
for index := range s.Metadata {
row := &s.Metadata[index]
if report.IsCommandEntry(row.ID) {
row.Value = report.StripCommandArgs(row.Value)
}
}
s.Tables = tables
}
if cfg.HideCommandLineArguments {
for r := range s.Metadata {
if isCommand(s.Metadata[r].ID) {
s.Metadata[r].Value = report.StripCommandArgs(s.Metadata[r].Value)
if cfg.HideEnvironmentVariables {
// Go through all the tables and if environment variables
// table is found, drop it from the list and stop the loop.
for index, table := range s.Tables {
if report.IsEnvironmentVarsEntry(table.ID) {
s.Tables = append(s.Tables[:index], s.Tables[index+1:]...)
break
}
}
}
}
// CensorNode ...
// CensorNode removes any sensitive data from a node.
func CensorNode(n Node, cfg report.CensorConfig) Node {
censorNodeSummary(&n.NodeSummary, cfg)
return n
}
// CensorNodeSummaries ...
// CensorNodeSummaries removes any sensitive data from a list of node summaries.
func CensorNodeSummaries(ns NodeSummaries, cfg report.CensorConfig) NodeSummaries {
for key := range ns {
n := ns[key]
censorNodeSummary(&n, cfg)
ns[key] = n
for key, summary := range ns {
censorNodeSummary(&summary, cfg)
ns[key] = summary
}
return ns
}