serviceaccounts.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package models
  2. import "sync"
  3. type ServiceAccountStatus struct {
  4. Checks []*ServiceAccountCheck `json:"checks"`
  5. }
  6. // ServiceAccountChecks is a thread safe map for holding ServiceAccountCheck objects
  7. type ServiceAccountChecks struct {
  8. sync.RWMutex
  9. serviceAccountChecks map[string]*ServiceAccountCheck
  10. }
  11. // NewServiceAccountChecks initialize ServiceAccountChecks
  12. func NewServiceAccountChecks() *ServiceAccountChecks {
  13. return &ServiceAccountChecks{
  14. serviceAccountChecks: make(map[string]*ServiceAccountCheck),
  15. }
  16. }
  17. func (sac *ServiceAccountChecks) Set(key string, check *ServiceAccountCheck) {
  18. sac.Lock()
  19. defer sac.Unlock()
  20. sac.serviceAccountChecks[key] = check
  21. }
  22. // getStatus extracts ServiceAccountCheck objects into a slice and returns them in a ServiceAccountStatus
  23. func (sac *ServiceAccountChecks) GetStatus() *ServiceAccountStatus {
  24. sac.Lock()
  25. defer sac.Unlock()
  26. checks := []*ServiceAccountCheck{}
  27. for _, v := range sac.serviceAccountChecks {
  28. checks = append(checks, v)
  29. }
  30. return &ServiceAccountStatus{
  31. Checks: checks,
  32. }
  33. }
  34. type ServiceAccountCheck struct {
  35. Message string `json:"message"`
  36. Status bool `json:"status"`
  37. AdditionalInfo string `json:"additionalInfo"`
  38. }