Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regex blob rename middleware #495

Merged
merged 3 commits into from
Oct 3, 2023
Merged

Add regex blob rename middleware #495

merged 3 commits into from
Oct 3, 2023

Conversation

rsrdesarrollo
Copy link

@rsrdesarrollo rsrdesarrollo commented Jan 31, 2023

Introduction

This is probably a crazy idea, but I needed s3proxy to be able to rename the names of the blobs before they were written, so I have developed this middleware, and I am sharing it in case it might be useful to someone else.

Use case

In our case, we have a product that can only talk to S3, uploading blobs in a very limited way, with almost no configuration. Originally, blobs were uploaded to /prefix/<source>/<YYYYYY>/<MM>/<DD> (e.g. /prefix/typea/2023/01/31). But due to other integrations that are not relevant, we needed the blobs to be uploaded in a path with the following format:

/prefix/date=<YYYY>-<MM>-<DD>/type=<source>

Configuration of middleware

The regex is configured as:

s3proxy.regex-blobstore.match.<regex name> = <regex match expression>
s3proxy.regex-blobstore.replace.<regex name> = <regex replace expression>

You can use multiple regex, and they are evaluated in order. The first regex that matches breaks the evaluation.

For example, for the use case previously mentioned, we have the following rule:

s3proxy.regex-blobstore.match.type_partition=^prefix/(\\w+)/(\\d{4})/(\\d{2})/(\\d{2})/(.*)$
s3proxy.regex-blobstore.replace.type_partition=prefix/date=$2-$3-$4/type=$1/$5

I would love to have your feedback regarding this middleware, as well as possible things I might have overlooked when implementing it.

Thank you very much for your project.

@gaul gaul requested a review from timuralp February 1, 2023 12:03
Copy link
Owner

@gaul gaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good idea! Before I review this, can you add some tests? Also add a blurb to the README and wiki explaining how to use this.

@rsrdesarrollo
Copy link
Author

Yes, no problem there is the wiki page
https://github.com/gaul/s3proxy/wiki/Middleware-regex

I will update README and test ASAP

@rsrdesarrollo
Copy link
Author

@gaul done

@gaul gaul merged commit 916af55 into gaul:master Oct 3, 2023
@gaul
Copy link
Owner

gaul commented Oct 3, 2023

Thank you for your contribution @rsrdesarrollo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants