@@ -51,6 +51,14 @@ type Options struct {
5151 // CreateBucket tells us to try to create the bucket
5252 CreateBucket bool `yaml:"create_bucket"`
5353
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+
5462 // EndpointURL can be set to something like "http://localhost:9000" when using Minio
5563 // or "https://s3.amazonaws.com" for AWS S3.
5664 EndpointURL string `yaml:"endpoint_url"`
@@ -110,6 +118,9 @@ type Backend struct {
110118}
111119
112120func (b * Backend ) List (ctx context.Context , prefix string ) (simpleblob.BlobList , error ) {
121+ // Prepend global prefix
122+ prefix = b .prependGlobalPrefix (prefix )
123+
113124 if ! b .opt .UseUpdateMarker {
114125 return b .doList (ctx , prefix )
115126 }
@@ -150,9 +161,12 @@ func (b *Backend) List(ctx context.Context, prefix string) (simpleblob.BlobList,
150161func (b * Backend ) doList (ctx context.Context , prefix string ) (simpleblob.BlobList , error ) {
151162 var blobs simpleblob.BlobList
152163
164+ // Runes to strip from blob names for GlobalPrefix
165+ gpEndRune := len (b .opt .GlobalPrefix )
166+
153167 objCh := b .client .ListObjects (ctx , b .opt .Bucket , minio.ListObjectsOptions {
154168 Prefix : prefix ,
155- Recursive : false ,
169+ Recursive : ! b . opt . PrefixFolders ,
156170 })
157171 for obj := range objCh {
158172 // Handle error returned by MinIO client
@@ -166,7 +180,14 @@ func (b *Backend) doList(ctx context.Context, prefix string) (simpleblob.BlobLis
166180 if obj .Key == UpdateMarkerFilename {
167181 continue
168182 }
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 })
170191 }
171192
172193 // 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
179200// Load retrieves the content of the object identified by name from S3 Bucket
180201// configured in b.
181202func (b * Backend ) Load (ctx context.Context , name string ) ([]byte , error ) {
203+ // Prepend global prefix
204+ name = b .prependGlobalPrefix (name )
205+
182206 metricCalls .WithLabelValues ("load" ).Inc ()
183207 metricLastCallTimestamp .WithLabelValues ("load" ).SetToCurrentTime ()
184208
@@ -199,6 +223,9 @@ func (b *Backend) Load(ctx context.Context, name string) ([]byte, error) {
199223// Store sets the content of the object identified by name to the content
200224// of data, in the S3 Bucket configured in b.
201225func (b * Backend ) Store (ctx context.Context , name string , data []byte ) error {
226+ // Prepend global prefix
227+ name = b .prependGlobalPrefix (name )
228+
202229 info , err := b .doStore (ctx , name , data )
203230 if err != nil {
204231 return err
@@ -222,6 +249,9 @@ func (b *Backend) doStore(ctx context.Context, name string, data []byte) (minio.
222249// Delete removes the object identified by name from the S3 Bucket
223250// configured in b.
224251func (b * Backend ) Delete (ctx context.Context , name string ) error {
252+ // Prepend global prefix
253+ name = b .prependGlobalPrefix (name )
254+
225255 if err := b .doDelete (ctx , name ); err != nil {
226256 return err
227257 }
@@ -370,6 +400,12 @@ func convertMinioError(err error) error {
370400 return nil
371401}
372402
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+
373409func init () {
374410 simpleblob .RegisterBackend ("s3" , func (ctx context.Context , p simpleblob.InitParams ) (simpleblob.Interface , error ) {
375411 var opt Options
0 commit comments