From 8967a0d1f5b0f0b67f66d5d472cda77af11e573f Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Tue, 26 Nov 2019 13:33:14 +0300 Subject: [PATCH 01/11] service: remove SignRequest, VerifyRequest and accompanying code --- service/sign.go | 47 ----------------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 service/sign.go diff --git a/service/sign.go b/service/sign.go deleted file mode 100644 index d8db94e8..00000000 --- a/service/sign.go +++ /dev/null @@ -1,47 +0,0 @@ -package service - -import ( - "crypto/ecdsa" - - crypto "github.com/nspcc-dev/neofs-crypto" - "github.com/nspcc-dev/neofs-proto/internal" - "github.com/pkg/errors" -) - -// ErrWrongSignature should be raised when wrong signature is passed into VerifyRequest. -const ErrWrongSignature = internal.Error("wrong signature") - -// SignedRequest interface allows sign and verify requests. -type SignedRequest interface { - PrepareData() ([]byte, error) - GetSignature() []byte - SetSignature([]byte) -} - -// SignRequest with passed private key. -func SignRequest(r SignedRequest, key *ecdsa.PrivateKey) error { - var signature []byte - if data, err := r.PrepareData(); err != nil { - return err - } else if signature, err = crypto.Sign(key, data); err != nil { - return errors.Wrap(err, "could not sign data") - } - - r.SetSignature(signature) - - return nil -} - -// VerifyRequest by passed public keys. -func VerifyRequest(r SignedRequest, keys ...*ecdsa.PublicKey) bool { - data, err := r.PrepareData() - if err != nil { - return false - } - for i := range keys { - if err := crypto.Verify(keys[i], data, r.GetSignature()); err == nil { - return true - } - } - return false -} From eda9ea38291220cd9354e8a0166f04f169c58d4b Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Tue, 26 Nov 2019 13:34:16 +0300 Subject: [PATCH 02/11] service: add method to RequestVerificationHeader to validate owner --- service/verify.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/service/verify.go b/service/verify.go index a6ac3a51..48e2871d 100644 --- a/service/verify.go +++ b/service/verify.go @@ -6,6 +6,7 @@ import ( "github.com/gogo/protobuf/proto" crypto "github.com/nspcc-dev/neofs-crypto" "github.com/nspcc-dev/neofs-proto/internal" + "github.com/nspcc-dev/neofs-proto/refs" "github.com/pkg/errors" ) @@ -35,6 +36,9 @@ const ( // ErrCannotFindOwner is raised when signatures empty in GetOwner. ErrCannotFindOwner = internal.Error("cannot find owner public key") + + // ErrWrongOwner is raised when passed OwnerID not equal to present PublicKey + ErrWrongOwner = internal.Error("wrong owner") ) // SetSignatures replaces signatures stored in RequestVerificationHeader. @@ -62,6 +66,18 @@ func (m *RequestVerificationHeader) SetOwner(pub *ecdsa.PublicKey, sign []byte) } } +// CheckOwner validates, that passed OwnerID is equal to present PublicKey of owner. +func (m *RequestVerificationHeader) CheckOwner(owner refs.OwnerID) error { + if key, err := m.GetOwner(); err != nil { + return err + } else if user, err := refs.NewOwnerID(key); err != nil { + return err + } else if !user.Equal(owner) { + return ErrWrongOwner + } + return nil +} + // GetOwner tries to get owner (client) public key from signatures. // If signatures contains not empty Origin, we should try to validate, // that session key was signed by owner (client), otherwise return error. From 40038cc860cbacfd0512dcc7a50245494a07556e Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Tue, 26 Nov 2019 13:42:47 +0300 Subject: [PATCH 03/11] service: test coverage for CheckOwner --- service/verify_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/service/verify_test.go b/service/verify_test.go index 1403c678..237e3623 100644 --- a/service/verify_test.go +++ b/service/verify_test.go @@ -9,6 +9,7 @@ import ( "github.com/gogo/protobuf/proto" crypto "github.com/nspcc-dev/neofs-crypto" "github.com/nspcc-dev/neofs-crypto/test" + "github.com/nspcc-dev/neofs-proto/refs" "github.com/pkg/errors" "github.com/stretchr/testify/require" ) @@ -78,6 +79,12 @@ func TestMaintainableRequest(t *testing.T) { } } + { // Validate owner + user, err := refs.NewOwnerID(&owner.PublicKey) + require.NoError(t, err) + require.NoError(t, req.CheckOwner(user)) + } + { // Good case: require.NoError(t, VerifyRequestHeader(req)) From 20c10a2afd5641a8f95394501949d5fef865f78c Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Tue, 26 Nov 2019 13:57:29 +0300 Subject: [PATCH 04/11] service: rename EpochRequest to EpochHeader and merge with MetaHeader --- service/epoch.go | 7 ------- service/meta.go | 11 ++++++++--- 2 files changed, 8 insertions(+), 10 deletions(-) delete mode 100644 service/epoch.go diff --git a/service/epoch.go b/service/epoch.go deleted file mode 100644 index 2fd43817..00000000 --- a/service/epoch.go +++ /dev/null @@ -1,7 +0,0 @@ -package service - -// EpochRequest interface gives possibility to get or set epoch in RPC Requests. -type EpochRequest interface { - GetEpoch() uint64 - SetEpoch(v uint64) -} diff --git a/service/meta.go b/service/meta.go index abffdadd..b41596a8 100644 --- a/service/meta.go +++ b/service/meta.go @@ -19,14 +19,19 @@ type ( GetTTL() uint32 SetTTL(uint32) - // EpochRequest gives possibility to get or set epoch in RPC Requests. - GetEpoch() uint64 - SetEpoch(uint64) + // EpochHeader gives possibility to get or set epoch in RPC Requests. + EpochHeader // VersionHeader allows get or set version of protocol request VersionHeader } + // EpochHeader interface gives possibility to get or set epoch in RPC Requests. + EpochHeader interface { + GetEpoch() uint64 + SetEpoch(v uint64) + } + // VersionHeader allows get or set version of protocol request VersionHeader interface { GetVersion() uint32 From d08f5a5811f0f19e7981bc3f60a391e7d722a261 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Tue, 26 Nov 2019 14:08:52 +0300 Subject: [PATCH 05/11] service: get status error even if it is wrapped --- service/meta.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/service/meta.go b/service/meta.go index abffdadd..c5d09f72 100644 --- a/service/meta.go +++ b/service/meta.go @@ -2,6 +2,7 @@ package service import ( "github.com/nspcc-dev/neofs-proto/internal" + "github.com/pkg/errors" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) @@ -101,7 +102,7 @@ func ProcessRequestTTL(req MetaHeader, cond ...TTLCondition) error { // check specific condition: if err := cond[i](ttl); err != nil { - if st, ok := status.FromError(err); ok { + if st, ok := status.FromError(errors.Cause(err)); ok { return st.Err() } From a893e389b0d9c2c58bc2d39e8691a1be5e85f256 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Tue, 26 Nov 2019 14:09:23 +0300 Subject: [PATCH 06/11] service: test coverage for wrapped status errors --- service/meta_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/service/meta_test.go b/service/meta_test.go index 496ea519..e208dfe1 100644 --- a/service/meta_test.go +++ b/service/meta_test.go @@ -3,6 +3,7 @@ package service import ( "testing" + "github.com/pkg/errors" "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -54,6 +55,18 @@ func TestMetaRequest(t *testing.T) { RequestMetaHeader: RequestMetaHeader{TTL: SingleForwardingTTL}, handler: func(_ uint32) error { return status.Error(codes.NotFound, "not found") }, }, + { + msg: "not found", + code: codes.NotFound, + name: "custom wrapped status error", + RequestMetaHeader: RequestMetaHeader{TTL: SingleForwardingTTL}, + handler: func(_ uint32) error { + err := status.Error(codes.NotFound, "not found") + err = errors.Wrap(err, "some error context") + err = errors.Wrap(err, "another error context") + return err + }, + }, } for i := range tests { From 5fa7d72bbad05acdc1eb2ec59e53183d1897a903 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Tue, 26 Nov 2019 15:53:55 +0300 Subject: [PATCH 07/11] service: get rid of signature field in accounting + proto generate --- accounting/withdraw.go | 6 ------ accounting/withdraw.pb.go | Bin 73944 -> 71346 bytes accounting/withdraw.proto | 4 ---- 3 files changed, 10 deletions(-) diff --git a/accounting/withdraw.go b/accounting/withdraw.go index 0a8cf901..11c56081 100644 --- a/accounting/withdraw.go +++ b/accounting/withdraw.go @@ -11,12 +11,6 @@ type ( MessageID = refs.MessageID ) -// SetSignature sets signature to PutRequest to satisfy SignedRequest interface. -func (m *PutRequest) SetSignature(v []byte) { m.Signature = v } - -// SetSignature sets signature to DeleteRequest to satisfy SignedRequest interface. -func (m *DeleteRequest) SetSignature(v []byte) { m.Signature = v } - // PrepareData prepares bytes representation of PutRequest to satisfy SignedRequest interface. func (m *PutRequest) PrepareData() ([]byte, error) { var offset int diff --git a/accounting/withdraw.pb.go b/accounting/withdraw.pb.go index a2116c01a729f0d2f6b3bcbaeedee0341339c404..d80b01cfdc9be61f60f0ff375dd852f07fde9e5d 100644 GIT binary patch delta 3693 zcmZXXIjdb&7=|&4T$5-pg+x$HY~_M`9tcE&O+e6A1cg0{g^ksLh&z>*f(KO8fPWxF zJfK)wS!iKlA*QxSkwUQ7wVr1gF4(NQ?;5`0{oZdlzyEmV+dF5z`R(b$-{+T8`+Juk z-!B&~9qvDK|Ma20^1(&7ul0}Zf31%=`nh`L^x^&P>d~nz+yC&=+uK|nU&(fL9oH$3 zYqP|4F5_BF$LG#wyF82kEFKJ8>bb;syYgMcHRpR`KV$7!moc7J2+i49k+5|c8aiGV z=oy=Mx5lu6HS6Ne&$+# z8_g{mv_&k+DT>QVK|<;PNFG$^?0}^7u{+#E(6;OFq-ATt{|>1mYc1w28Y=#&0kH$V z1TpRwz~G&k(;l4-`WqZfYWQBGo7-+gXg8ywLDGydt>4HfF)ULmz!>P3?+JMm1~n1b;yG$6-}10QP0zk4wE8b6 zbB=R081;p_@*@L)j8LvX+yk3X&F*7GM!;%=j(%O3rH4$)c%0YATd=+Z%7xe3SE8*l z8@U<^LA;4PLsDT~3oru`MuRSsO4Mms%`tr2o!p;C^tZ?^jS}G=@ld+e2pX^`<#o~F&Mh82%M_8X^P7#jSpEG{a+BF1`j5~kXWo9%o}8>4*(!%Uj|w;r9>om z;5O{3gjU{4iIi^h7H?S_%+ndT%_RxdpshoO8uI_?A2?m`TmppZ7P(p@uE7jb%tA0> zM&76&+y?BM^bnt|11A$o0;D>$szDb~E%fqWl^K}2A}%o*1=77J(C-6%OKFPP;aT*- zk|KSCBr})r!HjNzyCWDvxS+olD*1_n_82oPZ#OjbkYzxgb>9vmS*`nq*qt7E=2edW z$wqXhaO#4+!8&cDvc|0jVB=4X{)*MI+ah(q`c?u;BEARoS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zzu$TK|Mh47fj Date: Tue, 26 Nov 2019 15:54:27 +0300 Subject: [PATCH 08/11] service: get rid of signature field in container + proto generate --- container/service.go | 6 ------ container/service.pb.go | Bin 62382 -> 59764 bytes container/service.proto | 6 ------ 3 files changed, 12 deletions(-) diff --git a/container/service.go b/container/service.go index 4d3747e5..24727ee7 100644 --- a/container/service.go +++ b/container/service.go @@ -25,12 +25,6 @@ const ( ErrNotFound = internal.Error("could not find container") ) -// SetSignature sets signature to PutRequest to satisfy SignedRequest interface. -func (m *PutRequest) SetSignature(v []byte) { m.Signature = v } - -// SetSignature sets signature to DeleteRequest to satisfy SignedRequest interface. -func (m *DeleteRequest) SetSignature(v []byte) { m.Signature = v } - // PrepareData prepares bytes representation of PutRequest to satisfy SignedRequest interface. func (m *PutRequest) PrepareData() ([]byte, error) { var ( diff --git a/container/service.pb.go b/container/service.pb.go index 8b98cfa59116761173e6a5fa44f193826114d292..d9febc0e85a9d343fc30293765ae6c0f77e2f52d 100644 GIT binary patch delta 3486 zcmYk9JBwab6o$!!+(u$!R4hzVYhcd(Qd(FG{sB2x#Uh}MUn57bFa}b{`2nM43Pm_J zHmL=Rk+h1bf{lfsrGvEafJGYa=n8kIf;@Wp{ zP3O4gtX&?z8+KE6i$4C66>)9TxR&*u<7>$w;g8gxFlsO=IMyf8v|zUZa?wZ0A01o@ z50ufg;#-@v0%02BM#?(Z@jHW9*~IS}M-{shv{RfWSWY-CMl7*k+z_D`VTNVGeyJ@8 z4W7i2WQI)#TKzl@v}fX+vB|)%T0&^ps3Mu=Fu-X5p(RT>o+eJTQ{>#<4Q z1)-L820}~SMviqDHT+_&1`g-(z;Y0?$27sz5?7E+jRfBf>u8c{l3Q3ezFWR?V}twv zv56G6I0}bDI5TS=Pb~*))qpI$5N(uF3CjW>J*P{3^KEe(Xr~Zsu~%*r(OPIrIGZYv zL)s!h8V)Z(j_%+CPKO%CL2ohj>Kz*kU`i}chmE$+JHlD9K2nYjS9(`&~gh2yF>GGVwt+9vf%J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*^naqbd7!>~bYZ^#v!D0WcWx}yXTE=9e&@zD{||m9zfb@G diff --git a/container/service.proto b/container/service.proto index d4d50cae..8a3f56c0 100644 --- a/container/service.proto +++ b/container/service.proto @@ -41,9 +41,6 @@ message PutRequest { // Rules define storage policy for the object inside the container. netmap.PlacementRule rules = 4 [(gogoproto.nullable) = false]; - // Signature of the user (owner id) - bytes Signature = 5; - // RequestMetaHeader contains information about request meta headers (should be embedded into message) service.RequestMetaHeader Meta = 98 [(gogoproto.embed) = true, (gogoproto.nullable) = false]; // RequestVerificationHeader is a set of signatures of every NeoFS Node that processed request (should be embedded into message) @@ -59,9 +56,6 @@ message DeleteRequest { // CID (container id) is a SHA256 hash of the container structure bytes CID = 1 [(gogoproto.customtype) = "CID", (gogoproto.nullable) = false]; - // Signature of the container owner - bytes Signature = 2; - // RequestMetaHeader contains information about request meta headers (should be embedded into message) service.RequestMetaHeader Meta = 98 [(gogoproto.embed) = true, (gogoproto.nullable) = false]; // RequestVerificationHeader is a set of signatures of every NeoFS Node that processed request (should be embedded into message) From 7099e2083edd7e8c1249e0cb9348582bbf540cf3 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Tue, 26 Nov 2019 15:54:40 +0300 Subject: [PATCH 09/11] docs: regenerate documentation --- docs/accounting.md | 2 -- docs/container.md | 2 -- 2 files changed, 4 deletions(-) diff --git a/docs/accounting.md b/docs/accounting.md index 268a1872..bcae1366 100644 --- a/docs/accounting.md +++ b/docs/accounting.md @@ -362,7 +362,6 @@ Delete allows user to remove unused cheque | ID | [bytes](#bytes) | | ID is cheque identifier | | OwnerID | [bytes](#bytes) | | OwnerID is a wallet address | | MessageID | [bytes](#bytes) | | MessageID is a nonce for uniq request (UUIDv4) | -| Signature | [bytes](#bytes) | | Signature is a signature of the sent request | | Meta | [service.RequestMetaHeader](#service.RequestMetaHeader) | | RequestMetaHeader contains information about request meta headers (should be embedded into message) | | Verify | [service.RequestVerificationHeader](#service.RequestVerificationHeader) | | RequestVerificationHeader is a set of signatures of every NeoFS Node that processed request (should be embedded into message) | @@ -450,7 +449,6 @@ DeleteResponse is empty | Amount | [decimal.Decimal](#decimal.Decimal) | | Amount of funds | | Height | [uint64](#uint64) | | Height is the neo blockchain height until the cheque is valid | | MessageID | [bytes](#bytes) | | MessageID is a nonce for uniq request (UUIDv4) | -| Signature | [bytes](#bytes) | | Signature is a signature of the sent request | | Meta | [service.RequestMetaHeader](#service.RequestMetaHeader) | | RequestMetaHeader contains information about request meta headers (should be embedded into message) | | Verify | [service.RequestVerificationHeader](#service.RequestVerificationHeader) | | RequestVerificationHeader is a set of signatures of every NeoFS Node that processed request (should be embedded into message) | diff --git a/docs/container.md b/docs/container.md index bc559ce2..ef2ba19a 100644 --- a/docs/container.md +++ b/docs/container.md @@ -92,7 +92,6 @@ List returns all user's containers | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | CID | [bytes](#bytes) | | CID (container id) is a SHA256 hash of the container structure | -| Signature | [bytes](#bytes) | | Signature of the container owner | | Meta | [service.RequestMetaHeader](#service.RequestMetaHeader) | | RequestMetaHeader contains information about request meta headers (should be embedded into message) | | Verify | [service.RequestVerificationHeader](#service.RequestVerificationHeader) | | RequestVerificationHeader is a set of signatures of every NeoFS Node that processed request (should be embedded into message) | @@ -165,7 +164,6 @@ via consensus in inner ring nodes | Capacity | [uint64](#uint64) | | Capacity defines amount of data that can be stored in the container (doesn't used for now). | | OwnerID | [bytes](#bytes) | | OwnerID is a wallet address | | rules | [netmap.PlacementRule](#netmap.PlacementRule) | | Rules define storage policy for the object inside the container. | -| Signature | [bytes](#bytes) | | Signature of the user (owner id) | | Meta | [service.RequestMetaHeader](#service.RequestMetaHeader) | | RequestMetaHeader contains information about request meta headers (should be embedded into message) | | Verify | [service.RequestVerificationHeader](#service.RequestVerificationHeader) | | RequestVerificationHeader is a set of signatures of every NeoFS Node that processed request (should be embedded into message) | From ac44e4bb9fa1e1adf7026f190cf08b37a3bb85b5 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Tue, 26 Nov 2019 15:48:55 +0300 Subject: [PATCH 10/11] service: get rid of bytefmt - add ByteSize type + Stringer - add test coverage - cleanup modules closes #22 --- go.mod | 5 +---- go.sum | 20 ++---------------- object/utils.go | 35 ++++++++++++++++++++++++++++++-- object/utils_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 24 deletions(-) create mode 100644 object/utils_test.go diff --git a/go.mod b/go.mod index 06fb5c07..dc07a30b 100644 --- a/go.mod +++ b/go.mod @@ -3,16 +3,13 @@ module github.com/nspcc-dev/neofs-proto go 1.13 require ( - code.cloudfoundry.org/bytefmt v0.0.0-20190819182555-854d396b647c github.com/gogo/protobuf v1.3.1 github.com/golang/protobuf v1.3.2 github.com/google/uuid v1.1.1 - github.com/mr-tron/base58 v1.1.2 + github.com/mr-tron/base58 v1.1.3 github.com/nspcc-dev/neofs-crypto v0.2.2 github.com/nspcc-dev/netmap v1.6.1 github.com/nspcc-dev/tzhash v1.3.0 - github.com/onsi/ginkgo v1.10.2 // indirect - github.com/onsi/gomega v1.7.0 // indirect github.com/pkg/errors v0.8.1 github.com/prometheus/client_golang v1.2.1 github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 diff --git a/go.sum b/go.sum index f06a4990..13842ce9 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,4 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -code.cloudfoundry.org/bytefmt v0.0.0-20190819182555-854d396b647c h1:2RuXx1+tSNWRjxhY0Bx52kjV2odJQ0a6MTbfTPhGAkg= -code.cloudfoundry.org/bytefmt v0.0.0-20190819182555-854d396b647c/go.mod h1:wN/zk7mhREp/oviagqUXY3EwuHhWyOvAdsn5Y4CzOrc= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/abiosoft/ishell v2.0.0+incompatible/go.mod h1:HQR9AqF2R3P4XXpMpI0NAzgHf/aS6+zVXRj14cVk9qg= github.com/abiosoft/readline v0.0.0-20180607040430-155bce2042db/go.mod h1:rB3B4rKii8V21ydCbIzH5hZiCQE7f5E9SzUb/ZZx530= @@ -25,8 +23,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:rZfgFAXFS/z/lEd6LJmf9HVZ1LkgYiHx5pHhV5DR16M= -github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= @@ -49,8 +45,6 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= @@ -68,6 +62,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/mr-tron/base58 v1.1.2 h1:ZEw4I2EgPKDJ2iEw0cNmLB3ROrEmkOtXIkaG7wZg+78= github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= +github.com/mr-tron/base58 v1.1.3 h1:v+sk57XuaCKGXpWtVBX8YJzO7hMGx4Aajh4TQbdEFdc= +github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nspcc-dev/hrw v1.0.8 h1:vwRuJXZXgkMvf473vFzeWGCfY1WBVeSHAEHvR4u3/Cg= github.com/nspcc-dev/hrw v1.0.8/go.mod h1:l/W2vx83vMQo6aStyx2AuZrJ+07lGv2JQGlVkPG06MU= @@ -79,11 +75,6 @@ github.com/nspcc-dev/rfc6979 v0.1.0 h1:Lwg7esRRoyK1Up/IN1vAef1EmvrBeMHeeEkek2fAJ github.com/nspcc-dev/rfc6979 v0.1.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso= github.com/nspcc-dev/tzhash v1.3.0 h1:n6FTHsfPYbMi5Jmo6SwGVVRQD8i2w1P2ScCaW6rz69Q= github.com/nspcc-dev/tzhash v1.3.0/go.mod h1:Lc4DersKS8MNIrunTmsAzANO56qnG+LZ4GOE/WYGVzU= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.10.2 h1:uqH7bpe+ERSiDa34FDOF7RikN6RzXgduUF8yarlZp94= -github.com/onsi/ginkgo v1.10.2/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME= -github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -119,7 +110,6 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= @@ -127,12 +117,10 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190613194153-d28f0bde5980 h1:dfGZHvZk057jK2MCeWus/TowKpJ8y4AmooUzdBSR9GU= golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -155,10 +143,6 @@ gopkg.in/abiosoft/ishell.v2 v2.0.0/go.mod h1:sFp+cGtH6o4s1FtpVPTMcHq2yue+c4DGOVo gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/object/utils.go b/object/utils.go index c0fb6248..fab7fcc8 100644 --- a/object/utils.go +++ b/object/utils.go @@ -2,12 +2,43 @@ package object import ( "io" + "strconv" - "code.cloudfoundry.org/bytefmt" "github.com/nspcc-dev/neofs-proto/session" "github.com/pkg/errors" ) +// ByteSize used to format bytes +type ByteSize uint64 + +// String represents ByteSize in string format +func (b ByteSize) String() string { + var ( + dec int64 + unit string + num = int64(b) + ) + + switch { + case num > UnitsTB: + unit = "TB" + dec = UnitsTB + case num > UnitsGB: + unit = "GB" + dec = UnitsGB + case num > UnitsMB: + unit = "MB" + dec = UnitsMB + case num > UnitsKB: + unit = "KB" + dec = UnitsKB + case num > UnitsB: + dec = 1 + } + + return strconv.FormatFloat(float64(num)/float64(dec), 'g', 6, 64) + unit +} + // MakePutRequestHeader combines object and session token value // into header of object put request. func MakePutRequestHeader(obj *Object, token *session.Token) *PutRequest { @@ -26,7 +57,7 @@ func MakePutRequestChunk(chunk []byte) *PutRequest { } func errMaxSizeExceeded(size uint64) error { - return errors.Errorf("object payload size exceed: %s", bytefmt.ByteSize(size)) + return errors.Errorf("object payload size exceed: %s", ByteSize(size).String()) } // ReceiveGetResponse receives object by chunks from the protobuf stream diff --git a/object/utils_test.go b/object/utils_test.go new file mode 100644 index 00000000..a3f0162b --- /dev/null +++ b/object/utils_test.go @@ -0,0 +1,48 @@ +package object + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestByteSize_String(t *testing.T) { + var cases = []struct { + name string + expect string + actual ByteSize + }{ + { + name: "101 bytes", + expect: "101", + actual: ByteSize(101), + }, + { + name: "112.84KB", + expect: "112.84KB", + actual: ByteSize(115548), + }, + { + name: "80.44MB", + expect: "80.44MB", + actual: ByteSize(84347453), + }, + { + name: "905.144GB", + expect: "905.144GB", + actual: ByteSize(971891061884), + }, + { + name: "1.857TB", + expect: "1.857TB", + actual: ByteSize(2041793092780), + }, + } + + for i := range cases { + tt := cases[i] + t.Run(tt.name, func(t *testing.T) { + require.Equal(t, tt.expect, tt.actual.String()) + }) + } +} From b4df24aab9ddc62cb6dfcc3cf4b1210def1251b5 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Thu, 28 Nov 2019 20:22:34 +0300 Subject: [PATCH 11/11] CHANGELOG --- CHANGELOG.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e7736d6..a3f3c8ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,22 @@ # Changelog This is the changelog for NeoFS Proto +## [0.2.3] - 2019-11-28 + +### Removed +- service: SignRequest / VerifyRequest and accompanying code +- proto: Signature field from requests +- object: bytefmt package not used anymore + +### Changed +- service: rename EpochRequest to EpochHeader and merge with MetaHeader +- service: get status error even if it is wrapped + +### Added +- service: RequestVerificationHeader's method to validate owner +- service: test coverage for CheckOwner +- service: test coverage for wrapped status errors + ## [0.2.2] - 2019-11-22 ### Changed @@ -33,3 +49,4 @@ Initial public release [0.2.0]: https://github.com/nspcc-dev/neofs-proto/compare/v0.1.0...v0.2.0 [0.2.1]: https://github.com/nspcc-dev/neofs-proto/compare/v0.2.0...v0.2.1 [0.2.2]: https://github.com/nspcc-dev/neofs-proto/compare/v0.2.1...v0.2.2 +[0.2.3]: https://github.com/nspcc-dev/neofs-proto/compare/v0.2.2...v0.2.3