all: option to remove bucket name from prefix
All checks were successful
continuous-integration/drone Build is passing
All checks were successful
continuous-integration/drone Build is passing
default value for option to remove bucket name is `false`
This commit is contained in:
parent
9e01df4aff
commit
12a595ed74
4 changed files with 22 additions and 8 deletions
1
main.go
1
main.go
|
|
@ -117,6 +117,7 @@ func main() {
|
|||
"server_mode", serverMode,
|
||||
// Generic OBS
|
||||
"obs_bucket", defaultObsOpts.BucketName,
|
||||
"obs_remove_bucket_name", defaultObsOpts.RemoveBucketName,
|
||||
"obs_redirect_secure", defaultObsOpts.RedirectSecure,
|
||||
"obs_host_redirect", defaultObsOpts.HostRedirect,
|
||||
"obs_redirect_code", defaultObsOpts.RedirectCode,
|
||||
|
|
|
|||
9
obs.go
9
obs.go
|
|
@ -16,11 +16,14 @@ type obsOptions struct {
|
|||
RedirectCode int // HTTP redirect status code
|
||||
URLExpiry time.Duration
|
||||
HostRedirect string
|
||||
|
||||
RemoveBucketName bool
|
||||
}
|
||||
|
||||
var defaultObsOpts = obsOptions{
|
||||
URLExpiry: maxURLExpiry,
|
||||
RedirectCode: http.StatusMovedPermanently, // 301
|
||||
RemoveBucketName: false,
|
||||
}
|
||||
|
||||
func (opts *obsOptions) Bind(fs *flag.FlagSet) (err error) {
|
||||
|
|
@ -64,5 +67,11 @@ func (opts *obsOptions) Bind(fs *flag.FlagSet) (err error) {
|
|||
vObsUrlExpiry = obsUrlExpiry
|
||||
}
|
||||
fs.DurationVar(&opts.URLExpiry, "obs-url-expiry", vObsUrlExpiry, "OBS Redirection URL expiry")
|
||||
|
||||
var vObsRemoveBucketName = opts.RemoveBucketName
|
||||
if sObsRemoveBucketName := os.Getenv("OBS_REMOVE_BUCKET_NAME"); sObsRemoveBucketName != "" {
|
||||
vObsRemoveBucketName, _ = strconv.ParseBool(sObsRemoveBucketName)
|
||||
}
|
||||
fs.BoolVar(&opts.RemoveBucketName, "obs-remove-bucket-name", vObsRemoveBucketName, "OBS Remove Bucket name from prefix")
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,10 +73,12 @@ func (s *serverS3) handle(ctx *fasthttp.RequestCtx) {
|
|||
|
||||
path := ctx.Path()
|
||||
_path := bytes.TrimLeft(path, "/")
|
||||
if s.opts.RemoveBucketName {
|
||||
if _, _pathWithoutBucketName, found := bytes.Cut(_path, []byte(`/`)); found {
|
||||
// no need to check `isVirtualHostStyle` since this is our own implementation of handling request URI
|
||||
_path = _pathWithoutBucketName
|
||||
}
|
||||
}
|
||||
objectName := unsafeByteSliceToString(_path)
|
||||
|
||||
s.logger.Debugw("handle",
|
||||
|
|
|
|||
|
|
@ -62,10 +62,12 @@ func (s *serverStorj) handle(ctx *fasthttp.RequestCtx) {
|
|||
bucketName := s.opts.BucketName
|
||||
path := ctx.Path()
|
||||
_path := bytes.TrimLeft(path, "/")
|
||||
if s.opts.RemoveBucketName {
|
||||
if _, _pathWithoutBucketName, found := bytes.Cut(_path, []byte(`/`)); found {
|
||||
// no need to check `isVirtualHostStyle` since this is our own implementation of handling request URI
|
||||
_path = _pathWithoutBucketName
|
||||
}
|
||||
}
|
||||
objectName := unsafeByteSliceToString(_path)
|
||||
|
||||
s.logger.Debugw("handle",
|
||||
|
|
|
|||
Loading…
Reference in a new issue