-
Notifications
You must be signed in to change notification settings - Fork 22
/
buckets.go
60 lines (47 loc) · 1.25 KB
/
buckets.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
59
60
package storage
import (
"fmt"
"strings"
"github.com/genevieve/leftovers/common"
gcpstorage "google.golang.org/api/storage/v1"
)
//go:generate faux --interface bucketsClient --output fakes/buckets_client.go
type bucketsClient interface {
ListBuckets() (*gcpstorage.Buckets, error)
DeleteBucket(bucket string) error
ListObjects(bucket string) (*gcpstorage.Objects, error)
DeleteObject(bucket, object string, generation int64) error
}
type Buckets struct {
client bucketsClient
logger logger
}
func NewBuckets(client bucketsClient, logger logger) Buckets {
return Buckets{
client: client,
logger: logger,
}
}
func (i Buckets) List(filter string) ([]common.Deletable, error) {
i.logger.Debugln("Listing Storage Buckets...")
buckets, err := i.client.ListBuckets()
if err != nil {
return nil, fmt.Errorf("List Storage Buckets: %s", err)
}
var resources []common.Deletable
for _, bucket := range buckets.Items {
resource := NewBucket(i.client, bucket.Name)
if !strings.Contains(resource.Name(), filter) {
continue
}
proceed := i.logger.PromptWithDetails(resource.Type(), resource.Name())
if !proceed {
continue
}
resources = append(resources, resource)
}
return resources, nil
}
func (b Buckets) Type() string {
return "bucket"
}