-
Notifications
You must be signed in to change notification settings - Fork 12
/
interface.go
93 lines (77 loc) · 4.19 KB
/
interface.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2014 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package blobstore
import (
"io"
)
// ResourceStorage instances save and retrieve data from an underlying storage implementation.
type ResourceStorage interface {
// Get returns a reader for the resource located at path.
Get(path string) (io.ReadCloser, error)
// Put writes data from the specified reader to path and returns a checksum of the data written.
Put(path string, r io.Reader, length int64) (checksum string, err error)
// Remove deletes the data at the specified path.
Remove(path string) error
}
// ResourceCatalog instances persist Resources.
// Resources with the same hash values are not duplicated; instead a reference count is incremented.
// Similarly, when a Resource is removed, the reference count is decremented. When the reference
// count reaches zero, the Resource is deleted.
type ResourceCatalog interface {
// Get fetches a Resource with the given id.
Get(id string) (*Resource, error)
// Find returns the resource id for the Resource with the given hash.
Find(hash string) (id string, err error)
// Put ensures a Resource entry exists for the given hash,
// returning the id and path recorded by UploadComplete.
// If UploadComplete has not been called, path will be empty.
//
// If the Resource entry exists, its reference count is incremented,
// otherwise a new entry is created with a reference count of 1.
Put(hash string, length int64) (id, path string, err error)
// UploadComplete records that the underlying resource described by
// the Resource entry with id is now fully uploaded to the specified
// storage path, and the resource is available for use. If another
// uploader already recorded a path, then UploadComplete will return
// an error satisfiying juju/errors.IsAlreadyExists.
UploadComplete(id, path string) error
// Remove decrements the reference count for a Resource with the given id, deleting it
// if the reference count reaches zero. The path of the Resource is returned.
// If the Resource is deleted, wasDeleted is returned as true.
Remove(id string) (wasDeleted bool, path string, err error)
}
// ManagedStorage instances persist data for a bucket, for a user, or globally.
// (Only bucket storage is currently implemented).
type ManagedStorage interface {
// GetForBucket returns a reader for data at path, namespaced to the bucket.
// If the data is still being uploaded and is not fully written yet,
// an ErrUploadPending error is returned. This means the path is valid but the caller
// should try again to retrieve the data.
GetForBucket(bucketUUID, path string) (r io.ReadCloser, length int64, err error)
// PutForBucket stores data from reader at path, namespaced to the bucket.
//
// PutForBucket is equivalent to PutForBucketAndCheckHash with an empty
// hash string.
PutForBucket(bucketUUID, path string, r io.Reader, length int64) error
// PutForBucketAndCheckHash is the same as PutForBucket
// except that it also checks that the content matches the provided
// hash. The hash must be hex-encoded SHA-384.
//
// If checkHash is empty, then the hash check is elided.
//
// If length is < 0, then the reader will be consumed until EOF.
PutForBucketAndCheckHash(bucketUUID, path string, r io.Reader, length int64, checkHash string) error
// RemoveForBucket deletes data at path, namespaced to the bucket.
RemoveForBucket(bucketUUID, path string) error
// PutForBucketRequest requests that data, which may already exist in storage,
// be saved at path, namespaced to the bucket. It allows callers who can
// demonstrate proof of ownership of the data to store a reference to it without
// having to upload it all. If no such data exists, a NotFound error is returned
// and a call to bucket is required. If matching data is found, the caller
// is returned a response indicating the random byte range to for which they must
// provide a checksum to complete the process.
PutForBucketRequest(bucketUUID, path string, hash string) (*RequestResponse, error)
// ProofOfAccessResponse is called to respond to a Put..Request call in order to
// prove ownership of data for which a storage reference is created.
ProofOfAccessResponse(putResponse) error
}