Skip to content

Commit

Permalink
feat: allow enable/disable webdav-proxy with cli arg
Browse files Browse the repository at this point in the history
  • Loading branch information
saw-jan committed Jan 10, 2024
1 parent 19815a5 commit fd97c66
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
21 changes: 12 additions & 9 deletions cmd/serve/s3/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions cmd/serve/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var DefaultOpt = Options{
hashName: "MD5",
hashType: hash.MD5,
noCleanup: false,
asProxy: false,
HTTP: httplib.DefaultCfg(),
}

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmd/serve/s3/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Options struct {
hashType hash.Type
authPair []string
noCleanup bool
asProxy bool
HTTP httplib.Config
}

Expand Down

0 comments on commit fd97c66

Please sign in to comment.