From 3cbd4dbd097a39f3f086b8984de2e695a87d466f Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Tue, 26 Jan 2021 12:40:01 +0300 Subject: [PATCH] Fixes after review - Maybe it could be rephrased to "attribute name prefixed with X-Attribute-" - Maybe it worth renaming to userAttributeHeaderPrefix - Requirement for having only one file uploaded at a time has to be reflected in documentation. - Maybe this should be reflected in doc - I'm not sure if missing timestamp attribute should be forced on gateway level. Normally it should be set by app and there should be a way not to set it. Signed-off-by: Evgeniy Kulikov --- README.md | 17 +++++++++++++++-- app.go | 4 ++++ filter.go | 4 ++-- settings.go | 10 +++++++--- upload.go | 4 ++-- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c4652ed..d9f875b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # NeoFS HTTP Gate NeoFS HTTP Gate is example of tool that provides basic interactions with NeoFS. -You can download files from NeoFS Network using NeoFS Gate. + +- you can download one file per request from NeoFS Network using NeoFS Gate +- you can upload one file per request into NeoFS Network using NeoFS Gate ## Notable make targets @@ -24,6 +26,11 @@ You can download files from NeoFS Network using NeoFS Gate. ```go get -u github.com/nspcc-dev/neofs-http-gate``` +## File uploading behaviors + +- you can upload on file per request +- if `FileName` not provided by Header attributes, multipart/form filename will be used instead + ## Configuration ``` @@ -64,6 +71,8 @@ of Timeout and if no activity is seen even after that the connection is closed HTTP_GW_KEEPALIVE_PERMIT_WITHOUT_STREAM=Bool - if true, client sends keepalive pings even with no active RPCs. If false, when there are no active RPCs, Time and Timeout will be ignored and no keepalive pings will be sent. +HTTP_GW_UPLOAD_HEADER_USE_DEFAULT_TIMESTAMP=bool - enable/disable adding current timestamp attribute when object uploads + Peers preset: HTTP_GW_PEERS_[N]_ADDRESS = string @@ -71,6 +80,10 @@ HTTP_GW_PEERS_[N]_WEIGHT = 0..1 (float) Upload Header Table: -HTTP_GW_UPLOADER_HEADER_[N]_KEY = string - HTTP Header attribute name (except `X-Attribute-`) +HTTP_GW_UPLOADER_HEADER_[N]_KEY = string - HTTP Header attribute name prefixed with `X-Attribute-` HTTP_GW_UPLOADER_HEADER_[N]_VAL = string - NeoFS Object attribute mapping + +# By default we had next headers: +- FileName - to set object filename attribute +- Timestamp - to set object timestamp attribute ``` \ No newline at end of file diff --git a/app.go b/app.go index 57fff2e..f565793 100644 --- a/app.go +++ b/app.go @@ -33,6 +33,8 @@ type ( jobDone chan struct{} webDone chan struct{} + + enableDefaultTimestamp bool } App interface { @@ -78,6 +80,8 @@ func newApp(ctx context.Context, opt ...Option) App { a.hdr = newHeaderFilter(a.log, a.cfg) + a.enableDefaultTimestamp = a.cfg.GetBool(cfgUploaderHeaderEnableDefaultTimestamp) + a.wlog = logger.GRPC(a.log) if a.cfg.GetBool(cmdVerbose) { diff --git a/filter.go b/filter.go index 9c34015..2f12eb5 100644 --- a/filter.go +++ b/filter.go @@ -22,7 +22,7 @@ type ( } ) -const userAttributeHeader = "X-Attribute-" +const userAttributeHeaderPrefix = "X-Attribute-" func newHeaderFilter(l *zap.Logger, v *viper.Viper) HeaderFilter { filter := &headerFilter{ @@ -58,7 +58,7 @@ func newHeaderFilter(l *zap.Logger, v *viper.Viper) HeaderFilter { func (h *headerFilter) Filter(header *fasthttp.RequestHeader) map[string]string { result := make(map[string]string) - prefix := []byte(userAttributeHeader) + prefix := []byte(userAttributeHeaderPrefix) header.VisitAll(func(key, val []byte) { if len(key) == 0 || len(val) == 0 { diff --git a/settings.go b/settings.go index 2917a18..1775569 100644 --- a/settings.go +++ b/settings.go @@ -54,9 +54,10 @@ const ( cfgLoggerSamplingThereafter = "logger.sampling.thereafter" // Uploader Header - cfgUploaderHeader = "uploader_header" - cfgUploaderHeaderKey = "key" - cfgUploaderHeaderVal = "val" + cfgUploaderHeader = "uploader_header" + cfgUploaderHeaderKey = "key" + cfgUploaderHeaderVal = "val" + cfgUploaderHeaderEnableDefaultTimestamp = "upload_header.use_default_timestamp" // Peers cfgPeers = "peers" @@ -144,6 +145,9 @@ func settings() *viper.Viper { v.SetDefault(cfgWebWriteTimeout, time.Minute) v.SetDefault(cfgWebConnectionPerHost, 10) + // upload header + v.SetDefault(cfgUploaderHeaderEnableDefaultTimestamp, false) + if err := v.BindPFlags(flags); err != nil { panic(err) } diff --git a/upload.go b/upload.go index 0850cf6..b1330fc 100644 --- a/upload.go +++ b/upload.go @@ -124,8 +124,8 @@ func (a *app) upload(c *fasthttp.RequestCtx) { attributes = append(attributes, filename) } - // Attribute Timestamp wasn't set from header - if _, ok := filtered[object.AttributeTimestamp]; ok { + // Attribute Timestamp wasn't set from header and enabled by settings + if _, ok := filtered[object.AttributeTimestamp]; ok && a.enableDefaultTimestamp { timestamp := object.NewAttribute() timestamp.SetKey(object.AttributeTimestamp) timestamp.SetValue(strconv.FormatInt(time.Now().Unix(), 10))