/
api.go
171 lines (151 loc) · 5.72 KB
/
api.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
* Copyright 2018-2019, CS Systemes d'Information, http://www.c-s.fr
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package objectstorage
import (
"io"
"time"
)
const (
// RootPath defines the path corresponding of the root of a Bucket
RootPath = ""
// NoPrefix corresponds to ... no prefix...
NoPrefix = ""
)
//go:generate mockgen -destination=../mocks/mock_location.go -package=mocks github.com/CS-SI/SafeScale/lib/server/iaas/objectstorage Location
// Location ...
type Location interface {
// ReadTenant(projectName string, provider string) (Config, error)
GetType() string
//Inspect() (map[string][]string, error)
// SumSize() string
// Count(key string, pattern string) (int, error)
// WaitAllPutITemTerminated(key string, valuePattern string) error
// FilterByMetadata(key string, valuePattern string) (map[string][]string, error)
// ListBuckets returns all bucket prefixed by a string given as a parameter
ListBuckets(string) ([]string, error)
// FindBucket returns true of bucket exists in location
FindBucket(string) (bool, error)
// GetBucket returns info of the Bucket
GetBucket(string) (Bucket, error)
// Create a bucket
CreateBucket(string) (Bucket, error)
// DeleteBucket removes a bucket (need to be cleared before)
DeleteBucket(string) error
// ClearBucket empties a Bucket
ClearBucket(string, string, string) error
// ListObjects lists the objects in a Bucket
ListObjects(string, string, string) ([]string, error)
// GetObject ...
GetObject(string, string) (Object, error)
// ReadObject ...
ReadObject(string, string, io.Writer, int64, int64) error
// WriteMultiChunkObject ...
WriteMultiPartObject(string, string, io.Reader, int64, int, ObjectMetadata) (Object, error)
// WriteObject ...
WriteObject(string, string, io.Reader, int64, ObjectMetadata) (Object, error)
// // CopyObject copies an object
// CopyObject(string, string, string) error
// DeleteObject delete an object from a container
DeleteObject(string, string) error
// FilterItemsByMetadata(ContainerName string, key string, pattern string) (map[string][]string, error)
// // ItemSize ?
// ItemSize(ContainerName string, item string) (int64, error)
// // ItemEtag returns the Etag of an item
// ItemEtag(ContainerName string, item string) (string, error)
// // ItemLastMod returns the dagte of last update
// ItemLastMod(ContainerName string, item string) (time.Time, error)
// // ItemID returns the ID of the item
// ItemID(ContainerName string, item string) (id string)
// // ItemMetadata returns the metadata of an Item
// ItemMetadata(ContainerName string, item string) (map[string]interface{}, error)
}
//go:generate mockgen -destination=../mocks/mock_bucket.go -package=mocks github.com/CS-SI/SafeScale/lib/server/iaas/objectstorage Bucket
// Bucket interface
type Bucket interface {
// List list object names in a Bucket
List(string, string) ([]string, error)
// BrowseObjects browses inside the Bucket and execute a callback on each Object found
Browse(string, string, func(Object) error) error
// CreateObject creates a new object in the bucket
CreateObject(string) (Object, error)
// GetObject returns Object instance of an object in the Bucket
GetObject(string) (Object, error)
// DeleteObject delete an object from a container
DeleteObject(string) error
// ReadObject reads the content of an object
ReadObject(string, io.Writer, int64, int64) (Object, error)
// WriteObject writes into an object
WriteObject(string, io.Reader, int64, ObjectMetadata) (Object, error)
// WriteMultiPartObject writes a lot of data into an object, cut in pieces
WriteMultiPartObject(string, io.Reader, int64, int, ObjectMetadata) (Object, error)
// // CopyObject copies an object
// CopyObject(string, string) error
// GetName returns the name of the bucket
GetName() string
// GetCount returns the number of objects in the Bucket
GetCount(string, string) (int64, error)
// GetSize returns the total size of all objects in the bucket
GetSize(string, string) (int64, string, error)
}
// ObjectMetadata ...
type ObjectMetadata map[string]interface{}
// Clone creates a copy of ObjectMetadata
func (om ObjectMetadata) Clone() ObjectMetadata {
cloned := ObjectMetadata{}
for k, v := range om {
cloned[k] = v
}
return cloned
}
//go:generate mockgen -destination=../mocks/mock_object.go -package=mocks github.com/CS-SI/SafeScale/lib/server/iaas/objectstorage Object
// Object interface
type Object interface {
Stored() bool
Read(io.Writer, int64, int64) error
Write(io.Reader, int64) error
WriteMultiPart(io.Reader, int64, int) error
Reload() error
Delete() error
AddMetadata(ObjectMetadata)
ForceAddMetadata(ObjectMetadata)
ReplaceMetadata(ObjectMetadata)
GetID() string
GetName() string
GetLastUpdate() (time.Time, error)
GetSize() int64
GetETag() string
GetMetadata() ObjectMetadata
}
// FIXME GCP Remove specific driver code
// Config ...
type Config struct {
Type string
EnvAuth bool
AuthVersion int
AuthURL string
EndpointType string
Endpoint string
TenantDomain string
Tenant string
Domain string
User string
Key string
SecretKey string
Region string
AvailabilityZone string
ProjectID string
Credentials string
}