forked from TrueCloudLab/frostfs-api-go
[#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 <leonard@nspcc.ru>
This commit is contained in:
parent
dac997b8c3
commit
92e8376f39
3 changed files with 121 additions and 2 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue