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

Subdir in S3? #716

Open
flozano opened this issue Apr 12, 2023 · 2 comments
Open

Subdir in S3? #716

flozano opened this issue Apr 12, 2023 · 2 comments

Comments

@flozano
Copy link

flozano commented Apr 12, 2023

Is there any way to create a FS that accesses only a subdir in S3? (basically a prefix/ to everything)

@flozano
Copy link
Author

flozano commented Apr 12, 2023

Small edit for clarification: I have seen afero.NewBasePathFs but I am not sure if it is a good direction

@flozano
Copy link
Author

flozano commented Apr 12, 2023

diff --git a/fs/s3/s3.go b/fs/s3/s3.go
index b4756f8..ae2e413 100644
--- a/fs/s3/s3.go
+++ b/fs/s3/s3.go
@@ -18,6 +18,7 @@ func LoadFs(access *confpar.Access) (afero.Fs, error) {
        bucket := access.Params["bucket"]
        keyID := access.Params["access_key_id"]
        secretAccessKey := access.Params["secret_access_key"]
+       basePath := access.Params["base_path"]

        conf := aws.Config{
                Region:           aws.String(region),
@@ -42,6 +43,9 @@ func LoadFs(access *confpar.Access) (afero.Fs, error) {
        s3Fs := s3.NewFs(bucket, sess)

        // s3Fs = stripprefix.NewStripPrefixFs(s3Fs, 1)
-
-       return s3Fs, nil
+       if basePath != "" {
+               return afero.NewBasePathFs(s3Fs, basePath), nil
+       } else {
+               return s3Fs, nil
+       }
 }

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

No branches or pull requests

1 participant