Made censoring work properly.

This commit is contained in:
Filip Barl
2019-02-21 16:46:17 +01:00
parent 0f1b7e5972
commit 2c56ec2bf1
2 changed files with 37 additions and 8 deletions

View File

@@ -4,12 +4,41 @@ 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)
}
}
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)
}
}
}
}
// CensorNode ...
func CensorNode(n Node, cfg report.CensorConfig) Node {
censorNodeSummary(&n.NodeSummary, cfg)
return n
}
// CensorNodeSummaries ...
func CensorNodeSummaries(n NodeSummaries, cfg report.CensorConfig) NodeSummaries {
return n
func CensorNodeSummaries(ns NodeSummaries, cfg report.CensorConfig) NodeSummaries {
for key := range ns {
n := ns[key]
censorNodeSummary(&n, cfg)
ns[key] = n
}
return ns
}

View File

@@ -36,15 +36,15 @@ func censorTopology(t *Topology, match keyMatcher, censor censorValueFunc) {
// CensorConfig describes how probe reports should
// be censored when rendered through the API.
type CensorConfig struct {
hideCommandLineArguments bool
hideEnvironmentVariables bool
HideCommandLineArguments bool
HideEnvironmentVariables bool
}
// GetCensorConfigFromQueryParams extracts censor config from request query params.
func GetCensorConfigFromQueryParams(req *http.Request) CensorConfig {
return CensorConfig{
hideCommandLineArguments: true || req.URL.Query().Get("hideCommandLineArguments") == "true",
hideEnvironmentVariables: true || req.URL.Query().Get("hideEnvironmentVariables") == "true",
HideCommandLineArguments: true || req.URL.Query().Get("hideCommandLineArguments") == "true",
HideEnvironmentVariables: true || req.URL.Query().Get("hideEnvironmentVariables") == "true",
}
}
@@ -54,11 +54,11 @@ func CensorRawReport(r Report, cfg CensorConfig) Report {
var (
makeEmpty = func(string) string { return "" }
)
if cfg.hideCommandLineArguments {
if cfg.HideCommandLineArguments {
censorTopology(&r.Process, keyEquals(Cmdline), StripCommandArgs)
censorTopology(&r.Container, keyEquals(DockerContainerCommand), StripCommandArgs)
}
if cfg.hideEnvironmentVariables {
if cfg.HideEnvironmentVariables {
censorTopology(&r.Container, keyStartsWith(DockerEnvPrefix), makeEmpty)
}
return r