/
endpoint.go
87 lines (77 loc) · 3.1 KB
/
endpoint.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
76
77
78
79
80
81
82
83
84
85
86
87
package statistics
import (
"context"
cs "github.com/cloudtrust/common-service"
errorhandler "github.com/cloudtrust/common-service/errors"
msg "github.com/cloudtrust/keycloak-bridge/internal/constants"
"github.com/go-kit/kit/endpoint"
)
// Endpoints exposed for path /events
type Endpoints struct {
GetActions endpoint.Endpoint
GetStatistics endpoint.Endpoint
GetStatisticsUsers endpoint.Endpoint
GetStatisticsAuthenticators endpoint.Endpoint
GetStatisticsAuthentications endpoint.Endpoint
GetStatisticsAuthenticationsLog endpoint.Endpoint
GetMigrationReport endpoint.Endpoint
}
// MakeGetActionsEndpoint creates an endpoint for GetActions
func MakeGetActionsEndpoint(ec Component) cs.Endpoint {
return func(ctx context.Context, req interface{}) (interface{}, error) {
return ec.GetActions(ctx)
}
}
// MakeGetStatisticsEndpoint makes the statistic summary endpoint.
func MakeGetStatisticsEndpoint(ec Component) cs.Endpoint {
return func(ctx context.Context, req interface{}) (interface{}, error) {
var m = req.(map[string]string)
return ec.GetStatistics(ctx, m["realm"])
}
}
// MakeGetStatisticsUsersEndpoint makes the statistic users summary endpoint.
func MakeGetStatisticsUsersEndpoint(ec Component) cs.Endpoint {
return func(ctx context.Context, req interface{}) (interface{}, error) {
var m = req.(map[string]string)
return ec.GetStatisticsUsers(ctx, m["realm"])
}
}
// MakeGetStatisticsAuthenticatorsEndpoint makes the statistic authenticators summary endpoint.
func MakeGetStatisticsAuthenticatorsEndpoint(ec Component) cs.Endpoint {
return func(ctx context.Context, req interface{}) (interface{}, error) {
var m = req.(map[string]string)
return ec.GetStatisticsAuthenticators(ctx, m["realm"])
}
}
// MakeGetStatisticsAuthenticationsEndpoint makes the statistic authentications per period summary endpoint.
func MakeGetStatisticsAuthenticationsEndpoint(ec Component) cs.Endpoint {
return func(ctx context.Context, req interface{}) (interface{}, error) {
var m = req.(map[string]string)
if _, ok := m["unit"]; !ok {
return nil, errorhandler.CreateMissingParameterError(msg.Unit)
}
var timeshift *string = nil
if timeshiftStr, ok := m["timeshift"]; ok {
timeshift = ×hiftStr
}
return ec.GetStatisticsAuthentications(ctx, m["realm"], m["unit"], timeshift)
}
}
// MakeGetStatisticsAuthenticationsLogEndpoint makes the statistic last authentications summary endpoint.
func MakeGetStatisticsAuthenticationsLogEndpoint(ec Component) cs.Endpoint {
return func(ctx context.Context, req interface{}) (interface{}, error) {
var m = req.(map[string]string)
_, ok := m["max"]
if !ok {
return nil, errorhandler.CreateMissingParameterError(msg.Max)
}
return ec.GetStatisticsAuthenticationsLog(ctx, m["realm"], m["max"])
}
}
// MakeGetMigrationReportEndpoint makes the migration reporting endpoint.
func MakeGetMigrationReportEndpoint(ec Component) cs.Endpoint {
return func(ctx context.Context, req interface{}) (interface{}, error) {
var m = req.(map[string]string)
return ec.GetMigrationReport(ctx, m["realm"])
}
}