From 9cd4ef1ac424b62f84be89db335b2db6f36e9a9b Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Wed, 7 Sep 2022 09:59:24 +0300 Subject: [PATCH] [#657] Replace FileName with FilePath attribute Signed-off-by: Denis Kirillov --- api/cache/system.go | 2 +- api/handler/acl.go | 4 ++-- api/handler/acl_test.go | 14 +++++++------- api/handler/head.go | 2 +- api/layer/cors.go | 4 ++-- api/layer/neofs.go | 4 ++-- api/layer/neofs_mock.go | 6 +++--- api/layer/notifications.go | 2 +- api/layer/object.go | 10 +++++----- api/layer/util.go | 8 ++++---- creds/tokens/credentials.go | 6 +++--- docs/aws_cli.md | 2 +- internal/neofs/neofs.go | 10 +++++----- 13 files changed, 37 insertions(+), 37 deletions(-) diff --git a/api/cache/system.go b/api/cache/system.go index cf091584..fca798af 100644 --- a/api/cache/system.go +++ b/api/cache/system.go @@ -11,7 +11,7 @@ import ( // SystemCache provides lru cache for objects. // This cache contains "system" objects (bucket versioning settings, tagging object etc.). -// Key is bucketName+systemFileName. +// Key is bucketName+systemFilePath. type SystemCache struct { cache gcache.Cache logger *zap.Logger diff --git a/api/handler/acl.go b/api/handler/acl.go index dba40357..22823022 100644 --- a/api/handler/acl.go +++ b/api/handler/acl.go @@ -675,7 +675,7 @@ func resInfoFromFilters(bucketName string, filters []eacl.Filter) resourceInfo { resInfo := resourceInfo{Bucket: bucketName} for _, filter := range filters { if filter.Matcher() == eacl.MatchStringEqual { - if filter.Key() == object.AttributeFileName { + if filter.Key() == object.AttributeFilePath { resInfo.Object = filter.Value() } else if filter.Key() == v2acl.FilterObjectID { resInfo.Version = filter.Value() @@ -938,7 +938,7 @@ func formRecords(resource *astResource) ([]*eacl.Record, error) { } record.AddObjectIDFilter(eacl.MatchStringEqual, id) } else { - record.AddObjectAttributeFilter(eacl.MatchStringEqual, object.AttributeFileName, resource.Object) + record.AddObjectAttributeFilter(eacl.MatchStringEqual, object.AttributeFilePath, resource.Object) } } res = append(res, record) diff --git a/api/handler/acl_test.go b/api/handler/acl_test.go index 84b2df35..28a12bba 100644 --- a/api/handler/acl_test.go +++ b/api/handler/acl_test.go @@ -41,7 +41,7 @@ func TestTableToAst(t *testing.T) { record2.SetOperation(eacl.OperationPut) // Unknown role is used, because it is ignored when keys are set eacl.AddFormedTarget(record2, eacl.RoleUnknown, *(*ecdsa.PublicKey)(key.PublicKey()), *((*ecdsa.PublicKey)(key2.PublicKey()))) - record2.AddObjectAttributeFilter(eacl.MatchStringEqual, object.AttributeFileName, "objectName") + record2.AddObjectAttributeFilter(eacl.MatchStringEqual, object.AttributeFilePath, "objectName") record2.AddObjectIDFilter(eacl.MatchStringEqual, id) table.AddRecord(record2) @@ -480,12 +480,12 @@ func TestOrder(t *testing.T) { objectUsersPutRec := eacl.NewRecord() objectUsersPutRec.SetOperation(eacl.OperationPut) objectUsersPutRec.SetAction(eacl.ActionAllow) - objectUsersPutRec.AddObjectAttributeFilter(eacl.MatchStringEqual, object.AttributeFileName, objectName) + objectUsersPutRec.AddObjectAttributeFilter(eacl.MatchStringEqual, object.AttributeFilePath, objectName) objectUsersPutRec.SetTargets(*targetUser) objectOtherPutRec := eacl.NewRecord() objectOtherPutRec.SetOperation(eacl.OperationPut) objectOtherPutRec.SetAction(eacl.ActionDeny) - objectOtherPutRec.AddObjectAttributeFilter(eacl.MatchStringEqual, object.AttributeFileName, objectName) + objectOtherPutRec.AddObjectAttributeFilter(eacl.MatchStringEqual, object.AttributeFilePath, objectName) objectOtherPutRec.SetTargets(*targetOther) expectedEacl := eacl.NewTable() @@ -528,7 +528,7 @@ func TestOrder(t *testing.T) { childRecord.SetOperation(eacl.OperationDelete) childRecord.SetAction(eacl.ActionDeny) childRecord.SetTargets(*targetOther) - childRecord.AddObjectAttributeFilter(eacl.MatchStringEqual, object.AttributeFileName, childName) + childRecord.AddObjectAttributeFilter(eacl.MatchStringEqual, object.AttributeFilePath, childName) mergedAst, updated := mergeAst(expectedAst, child) require.True(t, updated) @@ -654,7 +654,7 @@ func TestAstToTable(t *testing.T) { record2.SetAction(eacl.ActionDeny) record2.SetOperation(eacl.OperationGet) eacl.AddFormedTarget(record2, eacl.RoleOthers) - record2.AddObjectAttributeFilter(eacl.MatchStringEqual, object.AttributeFileName, "objectName") + record2.AddObjectAttributeFilter(eacl.MatchStringEqual, object.AttributeFilePath, "objectName") expectedTable.AddRecord(serviceRec2.ToEACLRecord()) expectedTable.AddRecord(record2) @@ -895,7 +895,7 @@ func allowedTableForPrivateObject(t *testing.T, key *keys.PrivateKey, resInfo *r if isVersion { record.AddObjectIDFilter(eacl.MatchStringEqual, objID) } else { - record.AddObjectAttributeFilter(eacl.MatchStringEqual, object.AttributeFileName, resInfo.Object) + record.AddObjectAttributeFilter(eacl.MatchStringEqual, object.AttributeFilePath, resInfo.Object) } expectedTable.AddRecord(record) } @@ -905,7 +905,7 @@ func allowedTableForPrivateObject(t *testing.T, key *keys.PrivateKey, resInfo *r if isVersion { record.AddObjectIDFilter(eacl.MatchStringEqual, objID) } else { - record.AddObjectAttributeFilter(eacl.MatchStringEqual, object.AttributeFileName, resInfo.Object) + record.AddObjectAttributeFilter(eacl.MatchStringEqual, object.AttributeFilePath, resInfo.Object) } expectedTable.AddRecord(record) } diff --git a/api/handler/head.go b/api/handler/head.go index 84610933..e57b4c34 100644 --- a/api/handler/head.go +++ b/api/handler/head.go @@ -82,7 +82,7 @@ func (h *handler) HeadObjectHandler(w http.ResponseWriter, r *http.Request) { } if len(info.ContentType) == 0 { - if info.ContentType = layer.MimeByFileName(info.Name); len(info.ContentType) == 0 { + if info.ContentType = layer.MimeByFilePath(info.Name); len(info.ContentType) == 0 { buffer := bytes.NewBuffer(make([]byte, 0, sizeToDetectType)) getParams := &layer.GetObjectParams{ ObjectInfo: info, diff --git a/api/layer/cors.go b/api/layer/cors.go index e819f2d4..05a6b289 100644 --- a/api/layer/cors.go +++ b/api/layer/cors.go @@ -40,7 +40,7 @@ func (n *layer) PutBucketCORS(ctx context.Context, p *PutCORSParams) error { Container: p.BktInfo.CID, Creator: p.BktInfo.Owner, Payload: p.Reader, - Filename: p.BktInfo.CORSObjectName(), + Filepath: p.BktInfo.CORSObjectName(), CopiesNumber: p.CopiesNumber, } @@ -64,7 +64,7 @@ func (n *layer) PutBucketCORS(ctx context.Context, p *PutCORSParams) error { } } - if err := n.systemCache.PutCORS(systemObjectKey(p.BktInfo, prm.Filename), cors); err != nil { + if err = n.systemCache.PutCORS(systemObjectKey(p.BktInfo, prm.Filepath), cors); err != nil { n.log.Error("couldn't cache system object", zap.Error(err)) } diff --git a/api/layer/neofs.go b/api/layer/neofs.go index bbe88064..c7638e4f 100644 --- a/api/layer/neofs.go +++ b/api/layer/neofs.go @@ -100,8 +100,8 @@ type PrmObjectCreate struct { // Full payload size (optional). PayloadSize uint64 - // Associated filename (optional). - Filename string + // Associated filepath (optional). + Filepath string // Object payload encapsulated in io.Reader primitive. Payload io.Reader diff --git a/api/layer/neofs_mock.go b/api/layer/neofs_mock.go index ce3c6aea..8687e499 100644 --- a/api/layer/neofs_mock.go +++ b/api/layer/neofs_mock.go @@ -157,10 +157,10 @@ func (t *TestNeoFS) CreateObject(_ context.Context, prm PrmObjectCreate) (oid.ID attrs := make([]object.Attribute, 0) - if prm.Filename != "" { + if prm.Filepath != "" { a := object.NewAttribute() - a.SetKey(object.AttributeFileName) - a.SetValue(prm.Filename) + a.SetKey(object.AttributeFilePath) + a.SetValue(prm.Filepath) attrs = append(attrs, *a) } diff --git a/api/layer/notifications.go b/api/layer/notifications.go index 9cb0af00..62909907 100644 --- a/api/layer/notifications.go +++ b/api/layer/notifications.go @@ -31,7 +31,7 @@ func (n *layer) PutBucketNotificationConfiguration(ctx context.Context, p *PutBu Container: p.BktInfo.CID, Creator: p.BktInfo.Owner, Payload: bytes.NewReader(confXML), - Filename: sysName, + Filepath: sysName, CopiesNumber: p.CopiesNumber, } diff --git a/api/layer/object.go b/api/layer/object.go index f7d1585a..f36fab99 100644 --- a/api/layer/object.go +++ b/api/layer/object.go @@ -138,9 +138,9 @@ func (n *layer) objectGet(ctx context.Context, bktInfo *data.BucketInfo, objID o return res.Head, nil } -// MimeByFileName detect mime type by filename extension. -func MimeByFileName(name string) string { - ext := filepath.Ext(name) +// MimeByFilePath detect mime type by file path extension. +func MimeByFilePath(path string) string { + ext := filepath.Ext(path) if len(ext) == 0 { return "" } @@ -216,7 +216,7 @@ func (n *layer) PutObject(ctx context.Context, p *PutObjectParams) (*data.Object if r != nil { if len(p.Header[api.ContentType]) == 0 { - if contentType := MimeByFileName(p.Object); len(contentType) == 0 { + if contentType := MimeByFilePath(p.Object); len(contentType) == 0 { d := newDetector(r) if contentType, err := d.Detect(); err == nil { p.Header[api.ContentType] = contentType @@ -232,7 +232,7 @@ func (n *layer) PutObject(ctx context.Context, p *PutObjectParams) (*data.Object Container: p.BktInfo.CID, Creator: own, PayloadSize: uint64(p.Size), - Filename: p.Object, + Filepath: p.Object, Payload: r, CopiesNumber: p.CopiesNumber, } diff --git a/api/layer/util.go b/api/layer/util.go index 68c99e46..040dcd00 100644 --- a/api/layer/util.go +++ b/api/layer/util.go @@ -69,7 +69,7 @@ func objectInfoFromMeta(bkt *data.BucketInfo, meta *object.Object) *data.ObjectI ) headers := userHeaders(meta.Attributes()) - delete(headers, object.AttributeFileName) + delete(headers, object.AttributeFilePath) if contentType, ok := headers[object.AttributeContentType]; ok { mimeType = contentType delete(headers, object.AttributeContentType) @@ -89,7 +89,7 @@ func objectInfoFromMeta(bkt *data.BucketInfo, meta *object.Object) *data.ObjectI IsDir: false, Bucket: bkt.Name, - Name: filenameFromObject(meta), + Name: filepathFromObject(meta), Created: creation, ContentType: mimeType, Headers: headers, @@ -121,9 +121,9 @@ func addEncryptionHeaders(meta map[string]string, enc encryption.Params) error { return nil } -func filenameFromObject(o *object.Object) string { +func filepathFromObject(o *object.Object) string { for _, attr := range o.Attributes() { - if attr.Key() == object.AttributeFileName { + if attr.Key() == object.AttributeFilePath { return attr.Value() } } diff --git a/creds/tokens/credentials.go b/creds/tokens/credentials.go index c959d5d7..f1361a9d 100644 --- a/creds/tokens/credentials.go +++ b/creds/tokens/credentials.go @@ -37,8 +37,8 @@ type PrmObjectCreate struct { // NeoFS container to store the object. Container cid.ID - // File name. - Filename string + // File path. + Filepath string // Last NeoFS epoch of the object lifetime. ExpirationEpoch uint64 @@ -131,7 +131,7 @@ func (c *cred) Put(ctx context.Context, idCnr cid.ID, issuer user.ID, box *acces idObj, err := c.neoFS.CreateObject(ctx, PrmObjectCreate{ Creator: issuer, Container: idCnr, - Filename: strconv.FormatInt(time.Now().Unix(), 10) + "_access.box", + Filepath: strconv.FormatInt(time.Now().Unix(), 10) + "_access.box", ExpirationEpoch: expiration, Payload: data, }) diff --git a/docs/aws_cli.md b/docs/aws_cli.md index a8292083..03a3ec24 100644 --- a/docs/aws_cli.md +++ b/docs/aws_cli.md @@ -66,7 +66,7 @@ To upload a file into a bucket in the NeoFS network, run the following command: ``` $ aws s3api put-object --bucket %BUCKET_NAME --key %OBJECT_KEY --body %FILEPATH ``` -where %OBJECT_KEY is the filename of an object in NeoFS +where %OBJECT_KEY is the filepath of an object in NeoFS #### Upload of a dir diff --git a/internal/neofs/neofs.go b/internal/neofs/neofs.go index b7807f64..dc3fe5a1 100644 --- a/internal/neofs/neofs.go +++ b/internal/neofs/neofs.go @@ -218,7 +218,7 @@ func (x *NeoFS) DeleteContainer(ctx context.Context, id cid.ID, token *session.C func (x *NeoFS) CreateObject(ctx context.Context, prm layer.PrmObjectCreate) (oid.ID, error) { attrNum := len(prm.Attributes) + 1 // + creation time - if prm.Filename != "" { + if prm.Filepath != "" { attrNum++ } @@ -237,10 +237,10 @@ func (x *NeoFS) CreateObject(ctx context.Context, prm layer.PrmObjectCreate) (oi attrs = append(attrs, *a) } - if prm.Filename != "" { + if prm.Filepath != "" { a = object.NewAttribute() - a.SetKey(object.AttributeFileName) - a.SetValue(prm.Filename) + a.SetKey(object.AttributeFilePath) + a.SetValue(prm.Filepath) attrs = append(attrs, *a) } @@ -527,7 +527,7 @@ func (x *AuthmateNeoFS) CreateObject(ctx context.Context, prm tokens.PrmObjectCr return x.neoFS.CreateObject(ctx, layer.PrmObjectCreate{ Creator: prm.Creator, Container: prm.Container, - Filename: prm.Filename, + Filepath: prm.Filepath, Attributes: [][2]string{ {"__NEOFS__EXPIRATION_EPOCH", strconv.FormatUint(prm.ExpirationEpoch, 10)}}, Payload: bytes.NewReader(prm.Payload),