mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 17:51:21 +00:00
Made censoring work properly.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user