@@ -51,6 +51,14 @@ type Options struct {
51
51
// CreateBucket tells us to try to create the bucket
52
52
CreateBucket bool `yaml:"create_bucket"`
53
53
54
+ // GlobalPrefix is a prefix applied to all operations, allowing work within a prefix
55
+ // seamlessly
56
+ GlobalPrefix string `yaml:"global_prefix"`
57
+
58
+ // PrefixFolders can be enabled to make List operations show nested prefixes as folders
59
+ // instead of recursively listing all contents of nested prefixes
60
+ PrefixFolders bool `yaml:"prefix_folders"`
61
+
54
62
// EndpointURL can be set to something like "http://localhost:9000" when using Minio
55
63
// or "https://s3.amazonaws.com" for AWS S3.
56
64
EndpointURL string `yaml:"endpoint_url"`
@@ -110,6 +118,9 @@ type Backend struct {
110
118
}
111
119
112
120
func (b * Backend ) List (ctx context.Context , prefix string ) (simpleblob.BlobList , error ) {
121
+ // Prepend global prefix
122
+ prefix = b .prependGlobalPrefix (prefix )
123
+
113
124
if ! b .opt .UseUpdateMarker {
114
125
return b .doList (ctx , prefix )
115
126
}
@@ -150,9 +161,12 @@ func (b *Backend) List(ctx context.Context, prefix string) (simpleblob.BlobList,
150
161
func (b * Backend ) doList (ctx context.Context , prefix string ) (simpleblob.BlobList , error ) {
151
162
var blobs simpleblob.BlobList
152
163
164
+ // Runes to strip from blob names for GlobalPrefix
165
+ gpEndRune := len (b .opt .GlobalPrefix )
166
+
153
167
objCh := b .client .ListObjects (ctx , b .opt .Bucket , minio.ListObjectsOptions {
154
168
Prefix : prefix ,
155
- Recursive : false ,
169
+ Recursive : ! b . opt . PrefixFolders ,
156
170
})
157
171
for obj := range objCh {
158
172
// Handle error returned by MinIO client
@@ -166,7 +180,14 @@ func (b *Backend) doList(ctx context.Context, prefix string) (simpleblob.BlobLis
166
180
if obj .Key == UpdateMarkerFilename {
167
181
continue
168
182
}
169
- blobs = append (blobs , simpleblob.Blob {Name : obj .Key , Size : obj .Size })
183
+
184
+ // Strip global prefix from blob
185
+ blobName := obj .Key
186
+ if gpEndRune > 0 {
187
+ blobName = blobName [gpEndRune :]
188
+ }
189
+
190
+ blobs = append (blobs , simpleblob.Blob {Name : blobName , Size : obj .Size })
170
191
}
171
192
172
193
// Minio appears to return them sorted, but maybe not all implementations
@@ -179,6 +200,9 @@ func (b *Backend) doList(ctx context.Context, prefix string) (simpleblob.BlobLis
179
200
// Load retrieves the content of the object identified by name from S3 Bucket
180
201
// configured in b.
181
202
func (b * Backend ) Load (ctx context.Context , name string ) ([]byte , error ) {
203
+ // Prepend global prefix
204
+ name = b .prependGlobalPrefix (name )
205
+
182
206
metricCalls .WithLabelValues ("load" ).Inc ()
183
207
metricLastCallTimestamp .WithLabelValues ("load" ).SetToCurrentTime ()
184
208
@@ -199,6 +223,9 @@ func (b *Backend) Load(ctx context.Context, name string) ([]byte, error) {
199
223
// Store sets the content of the object identified by name to the content
200
224
// of data, in the S3 Bucket configured in b.
201
225
func (b * Backend ) Store (ctx context.Context , name string , data []byte ) error {
226
+ // Prepend global prefix
227
+ name = b .prependGlobalPrefix (name )
228
+
202
229
info , err := b .doStore (ctx , name , data )
203
230
if err != nil {
204
231
return err
@@ -222,6 +249,9 @@ func (b *Backend) doStore(ctx context.Context, name string, data []byte) (minio.
222
249
// Delete removes the object identified by name from the S3 Bucket
223
250
// configured in b.
224
251
func (b * Backend ) Delete (ctx context.Context , name string ) error {
252
+ // Prepend global prefix
253
+ name = b .prependGlobalPrefix (name )
254
+
225
255
if err := b .doDelete (ctx , name ); err != nil {
226
256
return err
227
257
}
@@ -370,6 +400,12 @@ func convertMinioError(err error) error {
370
400
return nil
371
401
}
372
402
403
+ // prependGlobalPrefix prepends the GlobalPrefix to the name/prefix
404
+ // passed as input
405
+ func (b * Backend ) prependGlobalPrefix (name string ) string {
406
+ return b .opt .GlobalPrefix + name
407
+ }
408
+
373
409
func init () {
374
410
simpleblob .RegisterBackend ("s3" , func (ctx context.Context , p simpleblob.InitParams ) (simpleblob.Interface , error ) {
375
411
var opt Options
0 commit comments