censor.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package detailed
  2. import (
  3. "github.com/weaveworks/scope/report"
  4. )
  5. func censorNodeSummary(s NodeSummary, cfg report.CensorConfig) NodeSummary {
  6. if cfg.HideCommandLineArguments && s.Metadata != nil {
  7. // Iterate through all the metadata rows and strip the
  8. // arguments from all the values containing a command
  9. // (while making sure everything is done in a non-mutable way).
  10. metadata := []report.MetadataRow{}
  11. for _, row := range s.Metadata {
  12. if report.IsCommandEntry(row.ID) {
  13. row.Value = report.StripCommandArgs(row.Value)
  14. }
  15. metadata = append(metadata, row)
  16. }
  17. s.Metadata = metadata
  18. }
  19. if cfg.HideEnvironmentVariables && s.Tables != nil {
  20. // Copy across all the tables except the environment
  21. // variable ones (ensuring the operation is non-mutable).
  22. tables := []report.Table{}
  23. for _, table := range s.Tables {
  24. if !report.IsEnvironmentVarsEntry(table.ID) {
  25. tables = append(tables, table)
  26. }
  27. }
  28. s.Tables = tables
  29. }
  30. return s
  31. }
  32. // CensorNode removes any sensitive data from a node.
  33. func CensorNode(node Node, cfg report.CensorConfig) Node {
  34. node.NodeSummary = censorNodeSummary(node.NodeSummary, cfg)
  35. return node
  36. }
  37. // CensorNodeSummaries removes any sensitive data from a list of node summaries.
  38. func CensorNodeSummaries(summaries NodeSummaries, cfg report.CensorConfig) NodeSummaries {
  39. censored := NodeSummaries{}
  40. for key := range summaries {
  41. censored[key] = censorNodeSummary(summaries[key], cfg)
  42. }
  43. return censored
  44. }