-
Notifications
You must be signed in to change notification settings - Fork 22
/
images.go
58 lines (45 loc) · 1.09 KB
/
images.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
package compute
import (
"fmt"
"strings"
"github.com/genevieve/leftovers/common"
gcpcompute "google.golang.org/api/compute/v1"
)
//go:generate faux --interface imagesClient --output fakes/images_client.go
type imagesClient interface {
ListImages() ([]*gcpcompute.Image, error)
DeleteImage(image string) error
}
type Images struct {
client imagesClient
logger logger
}
func NewImages(client imagesClient, logger logger) Images {
return Images{
client: client,
logger: logger,
}
}
func (i Images) List(filter string) ([]common.Deletable, error) {
i.logger.Debugln("Listing Images...")
images, err := i.client.ListImages()
if err != nil {
return nil, fmt.Errorf("List Images: %s", err)
}
var resources []common.Deletable
for _, image := range images {
resource := NewImage(i.client, image.Name)
if !strings.Contains(image.Name, filter) {
continue
}
proceed := i.logger.PromptWithDetails(resource.Type(), resource.Name())
if !proceed {
continue
}
resources = append(resources, resource)
}
return resources, nil
}
func (i Images) Type() string {
return "image"
}