-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
counters.go
73 lines (61 loc) · 1.69 KB
/
counters.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
package vault
import (
"context"
)
const (
requestCounterDatePathFormat = "2006/01"
// This storage path stores both the request counters in this file, and the activity log.
countersSubPath = "counters/"
)
// ActiveTokens contains the number of active tokens.
type ActiveTokens struct {
// ServiceTokens contains information about the number of active service
// tokens.
ServiceTokens TokenCounter `json:"service_tokens"`
}
// TokenCounter counts the number of tokens
type TokenCounter struct {
// Total is the total number of tokens
Total int `json:"total"`
}
// countActiveTokens returns the number of active tokens
func (c *Core) countActiveTokens(ctx context.Context) (*ActiveTokens, error) {
// Get all of the namespaces
ns := c.collectNamespaces()
// Count the tokens under each namespace
total := 0
for i := 0; i < len(ns); i++ {
ids, err := c.tokenStore.idView(ns[i]).List(ctx, "")
if err != nil {
return nil, err
}
total += len(ids)
}
return &ActiveTokens{
ServiceTokens: TokenCounter{
Total: total,
},
}, nil
}
// ActiveEntities contains the number of active entities.
type ActiveEntities struct {
// Entities contains information about the number of active entities.
Entities EntityCounter `json:"entities"`
}
// EntityCounter counts the number of entities
type EntityCounter struct {
// Total is the total number of entities
Total int `json:"total"`
}
// countActiveEntities returns the number of active entities
func (c *Core) countActiveEntities(ctx context.Context) (*ActiveEntities, error) {
count, err := c.identityStore.countEntities()
if err != nil {
return nil, err
}
return &ActiveEntities{
Entities: EntityCounter{
Total: count,
},
}, nil
}