From fd97c66b82fdb54658760886b7e1012d29c64c6e Mon Sep 17 00:00:00 2001 From: Saw-jan Date: Tue, 1 Aug 2023 17:56:17 +0545 Subject: [PATCH] feat: allow enable/disable webdav-proxy with cli arg --- cmd/serve/s3/backend.go | 21 ++++++++++++--------- cmd/serve/s3/s3.go | 2 ++ cmd/serve/s3/server.go | 1 + 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/cmd/serve/s3/backend.go b/cmd/serve/s3/backend.go index 4c7643697a22a..ff5c8a4a93770 100644 --- a/cmd/serve/s3/backend.go +++ b/cmd/serve/s3/backend.go @@ -41,15 +41,18 @@ func newBackend(opt *Options, w *Server) gofakes3.Backend { } func (b *s3Backend) setAuthForWebDAV(accessKey string) *vfs.VFS { - // new VFS - if _, ok := b.w.f.(*webdav.Fs); ok { - info, name, remote, config, _ := fs.ConfigFs(b.w.f.Name() + ":") - f, _ := info.NewFs(context.Background(), name+accessKey, remote, config) - vf := vfs.New(f, &vfsflags.Opt) - vf.Fs().(*webdav.Fs).SetBearerToken(accessKey) - return vf - } - return vfs.New(b.w.f, &vfsflags.Opt) + if b.opt.asProxy { + // new VFS + if _, ok := b.w.f.(*webdav.Fs); ok { + info, name, remote, config, _ := fs.ConfigFs(b.w.f.Name() + ":") + f, _ := info.NewFs(context.Background(), name+accessKey, remote, config) + vf := vfs.New(f, &vfsflags.Opt) + vf.Fs().(*webdav.Fs).SetBearerToken(accessKey) + return vf + } + return vfs.New(b.w.f, &vfsflags.Opt) + } + return b.w.vfs } // ListBuckets always returns the default bucket. diff --git a/cmd/serve/s3/s3.go b/cmd/serve/s3/s3.go index db9e384915265..293843f501593 100644 --- a/cmd/serve/s3/s3.go +++ b/cmd/serve/s3/s3.go @@ -19,6 +19,7 @@ var DefaultOpt = Options{ hashName: "MD5", hashType: hash.MD5, noCleanup: false, + asProxy: false, HTTP: httplib.DefaultCfg(), } @@ -35,6 +36,7 @@ func init() { flags.StringVarP(flagSet, &Opt.hashName, "etag-hash", "", Opt.hashName, "Which hash to use for the ETag, or auto or blank for off", "") flags.StringArrayVarP(flagSet, &Opt.authPair, "auth-key", "", Opt.authPair, "Set key pair for v4 authorization: access_key_id,secret_access_key", "") flags.BoolVarP(flagSet, &Opt.noCleanup, "no-cleanup", "", Opt.noCleanup, "Not to cleanup empty folder after object is deleted", "") + flags.BoolVarP(flagSet, &Opt.asProxy, "as-proxy", "", Opt.asProxy, "Serve as a proxy", "") } //go:embed serve_s3.md diff --git a/cmd/serve/s3/server.go b/cmd/serve/s3/server.go index 192c4d031d803..ec4584ec34334 100644 --- a/cmd/serve/s3/server.go +++ b/cmd/serve/s3/server.go @@ -24,6 +24,7 @@ type Options struct { hashType hash.Type authPair []string noCleanup bool + asProxy bool HTTP httplib.Config }