-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.go
75 lines (67 loc) · 2.05 KB
/
stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package compliance
import (
"context"
"github.com/chef/automate/components/automate-gateway/api/compliance/reporting/stats"
"github.com/chef/automate/components/automate-gateway/protobuf"
statsService "github.com/chef/automate/components/compliance-service/api/stats"
"github.com/golang/protobuf/proto"
)
type Stats struct {
client statsService.StatsServiceClient
}
func NewStatsHandler(statsClient statsService.StatsServiceClient) *Stats {
return &Stats{
client: statsClient,
}
}
// should cover /summary, /summary/nodes, /summary/controls
func (a *Stats) ReadSummary(ctx context.Context, in *stats.Query) (*stats.Summary, error) {
inDomain := &statsService.Query{}
out := &stats.Summary{}
f := func() (proto.Message, error) {
return a.client.ReadSummary(ctx, inDomain)
}
err := protobuf.CallDomainService(in, inDomain, f, out)
if err != nil {
return nil, err
}
return out, nil
}
// should cover /trend/nodes, /trend/controls
func (a *Stats) ReadTrend(ctx context.Context, in *stats.Query) (*stats.Trends, error) {
inDomain := &statsService.Query{}
out := &stats.Trends{}
f := func() (proto.Message, error) {
return a.client.ReadTrend(ctx, inDomain)
}
err := protobuf.CallDomainService(in, inDomain, f, out)
if err != nil {
return nil, err
}
return out, nil
}
// should cover /profiles, profiles/:profile-id/summary, profiles/:profile-id/controls
func (a *Stats) ReadProfiles(ctx context.Context, in *stats.Query) (*stats.Profile, error) {
inDomain := &statsService.Query{}
out := &stats.Profile{}
f := func() (proto.Message, error) {
return a.client.ReadProfiles(ctx, inDomain)
}
err := protobuf.CallDomainService(in, inDomain, f, out)
if err != nil {
return nil, err
}
return out, nil
}
func (a *Stats) ReadFailures(ctx context.Context, in *stats.Query) (*stats.Failures, error) {
inDomain := &statsService.Query{}
out := &stats.Failures{}
f := func() (proto.Message, error) {
return a.client.ReadFailures(ctx, inDomain)
}
err := protobuf.CallDomainService(in, inDomain, f, out)
if err != nil {
return nil, err
}
return out, nil
}