-
Notifications
You must be signed in to change notification settings - Fork 23
/
global_health_checks.go
55 lines (43 loc) · 1.18 KB
/
global_health_checks.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
package compute
import (
"fmt"
"strings"
"github.com/genevieve/leftovers/common"
gcpcompute "google.golang.org/api/compute/v1"
)
type globalHealthChecksClient interface {
ListGlobalHealthChecks() (*gcpcompute.HealthCheckList, error)
DeleteGlobalHealthCheck(globalHealthCheck string) error
}
type GlobalHealthChecks struct {
client globalHealthChecksClient
logger logger
}
func NewGlobalHealthChecks(client globalHealthChecksClient, logger logger) GlobalHealthChecks {
return GlobalHealthChecks{
client: client,
logger: logger,
}
}
func (h GlobalHealthChecks) List(filter string) ([]common.Deletable, error) {
checks, err := h.client.ListGlobalHealthChecks()
if err != nil {
return nil, fmt.Errorf("List Global Health Checks: %s", err)
}
var resources []common.Deletable
for _, check := range checks.Items {
resource := NewGlobalHealthCheck(h.client, check.Name)
if !strings.Contains(check.Name, filter) {
continue
}
proceed := h.logger.PromptWithDetails(resource.Type(), resource.Name())
if !proceed {
continue
}
resources = append(resources, resource)
}
return resources, nil
}
func (h GlobalHealthChecks) Type() string {
return "global-health-check"
}