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 <kim@nspcc.ru>
This commit is contained in:
Evgeniy Kulikov 2021-01-26 12:40:01 +03:00
parent ace31ceefd
commit 3cbd4dbd09
No known key found for this signature in database
GPG key ID: BF6AEE0A2A699BF2
5 changed files with 30 additions and 9 deletions

View file

@ -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
```

4
app.go
View file

@ -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) {

View file

@ -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 {

View file

@ -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)
}

View file

@ -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))