mirror of
https://github.com/weaveworks/scope.git
synced 2026-08-23 22:36:24 +00:00
Code cleanup.
This commit is contained in:
+19
-20
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user