From 92e8376f39aae298eb84cfe5d39cb312142a1ef4 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 24 May 2021 21:18:56 +0300 Subject: [PATCH] [#283] v2/container: Add session token and signature to response bodies Add field of type `session.SessionToken` to `GetResponseBody` and `GetExtendedACLResponseBody` messages. Add field of type `refs,Signature` to `GetResponseBody` message. Change the implementation of all related methods. Signed-off-by: Leonard Lyubich --- v2/container/convert.go | 38 +++++++++++++++++++++++++++ v2/container/marshal.go | 27 +++++++++++++++++-- v2/container/types.go | 58 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 2 deletions(-) diff --git a/v2/container/convert.go b/v2/container/convert.go index 5ef3fed..be0bb10 100644 --- a/v2/container/convert.go +++ b/v2/container/convert.go @@ -10,6 +10,8 @@ import ( netmapGRPC "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc" "github.com/nspcc-dev/neofs-api-go/v2/refs" refsGRPC "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc" + "github.com/nspcc-dev/neofs-api-go/v2/session" + sessionGRPC "github.com/nspcc-dev/neofs-api-go/v2/session/grpc" ) func (a *Attribute) ToGRPCMessage() grpc.Message { @@ -388,6 +390,8 @@ func (r *GetResponseBody) ToGRPCMessage() grpc.Message { m = new(container.GetResponse_Body) m.SetContainer(r.cnr.ToGRPCMessage().(*container.Container)) + m.SetSessionToken(r.token.ToGRPCMessage().(*sessionGRPC.SessionToken)) + m.SetSignature(r.sig.ToGRPCMessage().(*refsGRPC.Signature)) } return m @@ -412,6 +416,28 @@ func (r *GetResponseBody) FromGRPCMessage(m grpc.Message) error { err = r.cnr.FromGRPCMessage(cnr) } + sig := v.GetSignature() + if sig == nil { + r.sig = nil + } else { + if r.sig == nil { + r.sig = new(refs.Signature) + } + + err = r.sig.FromGRPCMessage(sig) + } + + token := v.GetSessionToken() + if token == nil { + r.token = nil + } else { + if r.token == nil { + r.token = new(session.SessionToken) + } + + err = r.token.FromGRPCMessage(token) + } + return err } @@ -956,6 +982,7 @@ func (r *GetExtendedACLResponseBody) ToGRPCMessage() grpc.Message { m.SetEacl(r.eacl.ToGRPCMessage().(*aclGRPC.EACLTable)) m.SetSignature(r.sig.ToGRPCMessage().(*refsGRPC.Signature)) + m.SetSessionToken(r.token.ToGRPCMessage().(*sessionGRPC.SessionToken)) } return m @@ -994,6 +1021,17 @@ func (r *GetExtendedACLResponseBody) FromGRPCMessage(m grpc.Message) error { err = r.sig.FromGRPCMessage(sig) } + token := v.GetSessionToken() + if token == nil { + r.token = nil + } else { + if r.token == nil { + r.token = new(session.SessionToken) + } + + err = r.token.FromGRPCMessage(token) + } + return err } diff --git a/v2/container/marshal.go b/v2/container/marshal.go index 3c0af3e..a53661d 100644 --- a/v2/container/marshal.go +++ b/v2/container/marshal.go @@ -28,6 +28,8 @@ const ( getReqBodyIDField = 1 getRespBodyContainerField = 1 + getRespBodySignatureField = 2 + getRespBodyTokenField = 3 listReqBodyOwnerField = 1 @@ -40,6 +42,7 @@ const ( getEACLRespBodyTableField = 1 getEACLRespBodySignatureField = 2 + getEACLRespBodyTokenField = 3 usedSpaceAnnounceEpochField = 1 usedSpaceAnnounceCIDField = 2 @@ -349,7 +352,17 @@ func (r *GetResponseBody) StableMarshal(buf []byte) ([]byte, error) { buf = make([]byte, r.StableSize()) } - _, err := protoutil.NestedStructureMarshal(getRespBodyContainerField, buf, r.cnr) + offset, err := protoutil.NestedStructureMarshal(getRespBodyContainerField, buf, r.cnr) + if err != nil { + return nil, err + } + + n, err := protoutil.NestedStructureMarshal(getRespBodySignatureField, buf[offset:], r.sig) + if err != nil { + return nil, err + } + + _, err = protoutil.NestedStructureMarshal(getRespBodyTokenField, buf[offset+n:], r.token) if err != nil { return nil, err } @@ -363,6 +376,8 @@ func (r *GetResponseBody) StableSize() (size int) { } size += protoutil.NestedStructureSize(getRespBodyContainerField, r.cnr) + size += protoutil.NestedStructureSize(getRespBodySignatureField, r.sig) + size += protoutil.NestedStructureSize(getRespBodyTokenField, r.token) return size } @@ -552,7 +567,14 @@ func (r *GetExtendedACLResponseBody) StableMarshal(buf []byte) ([]byte, error) { offset += n - _, err = protoutil.NestedStructureMarshal(getEACLRespBodySignatureField, buf[offset:], r.sig) + n, err = protoutil.NestedStructureMarshal(getEACLRespBodySignatureField, buf[offset:], r.sig) + if err != nil { + return nil, err + } + + offset += n + + _, err = protoutil.NestedStructureMarshal(getEACLRespBodyTokenField, buf[offset:], r.token) if err != nil { return nil, err } @@ -567,6 +589,7 @@ func (r *GetExtendedACLResponseBody) StableSize() (size int) { size += protoutil.NestedStructureSize(getEACLRespBodyTableField, r.eacl) size += protoutil.NestedStructureSize(getEACLRespBodySignatureField, r.sig) + size += protoutil.NestedStructureSize(getEACLRespBodyTokenField, r.token) return size } diff --git a/v2/container/types.go b/v2/container/types.go index a790f03..63449ef 100644 --- a/v2/container/types.go +++ b/v2/container/types.go @@ -58,6 +58,10 @@ type GetRequest struct { type GetResponseBody struct { cnr *Container + + token *session.SessionToken + + sig *refs.Signature } type GetResponse struct { @@ -140,6 +144,8 @@ type GetExtendedACLResponseBody struct { eacl *acl.Table sig *refs.Signature + + token *session.SessionToken } type GetExtendedACLResponse struct { @@ -398,6 +404,40 @@ func (r *GetResponseBody) SetContainer(v *Container) { } } +// GetSessionToken returns token of the session within which requested +// container was created. +func (r *GetResponseBody) GetSessionToken() *session.SessionToken { + if r != nil { + return r.token + } + + return nil +} + +// SetSessionToken sets token of the session within which requested +// container was created. +func (r *GetResponseBody) SetSessionToken(v *session.SessionToken) { + if r != nil { + r.token = v + } +} + +// GetSignature returns signature of the requested container. +func (r *GetResponseBody) GetSignature() *refs.Signature { + if r != nil { + return r.sig + } + + return nil +} + +// SetSignature sets signature of the requested container. +func (r *GetResponseBody) SetSignature(v *refs.Signature) { + if r != nil { + r.sig = v + } +} + func (r *GetResponse) GetBody() *GetResponseBody { if r != nil { return r.body @@ -636,6 +676,24 @@ func (r *GetExtendedACLResponseBody) SetSignature(v *refs.Signature) { } } +// GetSessionToken returns token of the session within which requested +// eACL table was set. +func (r *GetExtendedACLResponseBody) GetSessionToken() *session.SessionToken { + if r != nil { + return r.token + } + + return nil +} + +// SetSessionToken sets token of the session within which requested +// eACL table was set. +func (r *GetExtendedACLResponseBody) SetSessionToken(v *session.SessionToken) { + if r != nil { + r.token = v + } +} + func (r *GetExtendedACLResponse) GetBody() *GetExtendedACLResponseBody { if r != nil { return r.body