/
serviceaccounts.go
45 lines (38 loc) · 1.18 KB
/
serviceaccounts.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
package models
import "sync"
type ServiceAccountStatus struct {
Checks []*ServiceAccountCheck `json:"checks"`
}
// ServiceAccountChecks is a thread safe map for holding ServiceAccountCheck objects
type ServiceAccountChecks struct {
sync.RWMutex
serviceAccountChecks map[string]*ServiceAccountCheck
}
// NewServiceAccountChecks initialize ServiceAccountChecks
func NewServiceAccountChecks() *ServiceAccountChecks {
return &ServiceAccountChecks{
serviceAccountChecks: make(map[string]*ServiceAccountCheck),
}
}
func (sac *ServiceAccountChecks) Set(key string, check *ServiceAccountCheck) {
sac.Lock()
defer sac.Unlock()
sac.serviceAccountChecks[key] = check
}
// getStatus extracts ServiceAccountCheck objects into a slice and returns them in a ServiceAccountStatus
func (sac *ServiceAccountChecks) GetStatus() *ServiceAccountStatus {
sac.Lock()
defer sac.Unlock()
checks := []*ServiceAccountCheck{}
for _, v := range sac.serviceAccountChecks {
checks = append(checks, v)
}
return &ServiceAccountStatus{
Checks: checks,
}
}
type ServiceAccountCheck struct {
Message string `json:"message"`
Status bool `json:"status"`
AdditionalInfo string `json:"additionalInfo"`
}