Skip to content

Commit

Permalink
Made censoring work properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
fbarl committed Feb 21, 2019
1 parent 0f1b7e5 commit 2c56ec2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
33 changes: 31 additions & 2 deletions render/detailed/censor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
12 changes: 6 additions & 6 deletions report/censor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
}

Expand All @@ -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
Expand Down

0 comments on commit 2c56ec2

Please sign in to comment.