Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfonso Acosta committed Jul 4, 2016
1 parent c0d5c39 commit 1d2dd2b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
18 changes: 3 additions & 15 deletions probe/appclient/report_publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,12 @@ func NewReportPublisher(publisher Publisher, noControls bool) *ReportPublisher {
}
}

func removeControls(r report.Report) report.Report {
r.Endpoint.Controls = report.Controls{}
r.Process.Controls = report.Controls{}
r.Container.Controls = report.Controls{}
r.ContainerImage.Controls = report.Controls{}
r.Pod.Controls = report.Controls{}
r.Service.Controls = report.Controls{}
r.Deployment.Controls = report.Controls{}
r.ReplicaSet.Controls = report.Controls{}
r.Host.Controls = report.Controls{}
r.Overlay.Controls = report.Controls{}
return r
}

// Publish serialises and compresses a report, then passes it to a publisher
func (p *ReportPublisher) Publish(r report.Report) error {
if p.noControls {
r = removeControls(r)
r.WalkTopologies(func(t *report.Topology) {
t.Controls = report.Controls{}
})
}
buf := &bytes.Buffer{}
r.WriteBinary(buf)
Expand Down
32 changes: 20 additions & 12 deletions report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,26 @@ func (r Report) Merge(other Report) Report {

// Topologies returns a slice of Topologies in this report
func (r Report) Topologies() []Topology {
return []Topology{
r.Endpoint,
r.Process,
r.Container,
r.ContainerImage,
r.Pod,
r.Service,
r.Deployment,
r.ReplicaSet,
r.Host,
r.Overlay,
}
result := []Topology{}
r.WalkTopologies(func(t *Topology) {
result = append(result, *t)
})
return result
}

// WalkTopologies iterates through the Topologies of the report,
// potentially modifying them
func (r Report) WalkTopologies(f func(*Topology)) {
f(&r.Endpoint)
f(&r.Process)
f(&r.Container)
f(&r.ContainerImage)
f(&r.Pod)
f(&r.Service)
f(&r.Deployment)
f(&r.ReplicaSet)
f(&r.Host)
f(&r.Overlay)
}

// Topology gets a topology by name
Expand Down

0 comments on commit 1d2dd2b

Please sign in to comment.