-
Notifications
You must be signed in to change notification settings - Fork 23
/
https_health_checks.go
55 lines (43 loc) · 1.17 KB
/
https_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 httpsHealthChecksClient interface {
ListHttpsHealthChecks() (*gcpcompute.HttpsHealthCheckList, error)
DeleteHttpsHealthCheck(httpsHealthCheck string) error
}
type HttpsHealthChecks struct {
client httpsHealthChecksClient
logger logger
}
func NewHttpsHealthChecks(client httpsHealthChecksClient, logger logger) HttpsHealthChecks {
return HttpsHealthChecks{
client: client,
logger: logger,
}
}
func (h HttpsHealthChecks) List(filter string) ([]common.Deletable, error) {
checks, err := h.client.ListHttpsHealthChecks()
if err != nil {
return nil, fmt.Errorf("List Https Health Checks: %s", err)
}
var resources []common.Deletable
for _, check := range checks.Items {
resource := NewHttpsHealthCheck(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 HttpsHealthChecks) Type() string {
return "https-health-check"
}