This repository has been archived by the owner on Jun 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathstorageObjectPrefix.go
59 lines (50 loc) · 1.6 KB
/
storageObjectPrefix.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
package gcp
import (
"context"
"cloud.google.com/go/storage"
"github.com/puppetlabs/wash/plugin"
)
type storageObjectPrefix struct {
plugin.EntryBase
bucket *storage.BucketHandle
prefix string
}
// Takes the name of the directory, as well as the full prefix path.
// Attrs may be nil if they could not be retrieved. Some prefixes don't appear to have attributes.
func newStorageObjectPrefix(bucket *storage.BucketHandle,
name, prefix string, attrs *storage.ObjectAttrs) *storageObjectPrefix {
pre := &storageObjectPrefix{
EntryBase: plugin.NewEntry(name),
bucket: bucket,
prefix: prefix,
}
if attrs != nil {
pre.SetPartialMetadata(attrs).
Attributes().
SetCrtime(attrs.Created).
SetCtime(attrs.Updated).
SetMtime(attrs.Updated).
SetSize(uint64(attrs.Size))
}
return pre
}
// List all storage objects under this prefix as dirs and files.
func (s *storageObjectPrefix) List(ctx context.Context) ([]plugin.Entry, error) {
return listBucket(ctx, s.bucket, s.prefix)
}
func (s *storageObjectPrefix) Delete(ctx context.Context) (bool, error) {
err := deleteObjects(ctx, s.bucket, s.prefix)
return true, err
}
func (s *storageObjectPrefix) Schema() *plugin.EntrySchema {
return plugin.NewEntrySchema(s, "prefix").
SetDescription(storageObjectPrefixDescription).
SetPartialMetadataSchema(storage.ObjectAttrs{})
}
func (s *storageObjectPrefix) ChildSchemas() []*plugin.EntrySchema {
return bucketSchemas()
}
const storageObjectPrefixDescription = `
This represents a common prefix shared by multiple Storage objects. See
the bucket's docs for more details on why we have this kind of entry.
`