forked from TrueCloudLab/frostfs-api-go
[#350] v2/session: Support `status` field in `ResponseMetaHeader`
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>support/v2.15
parent
ca746f3800
commit
2d70391e31
|
@ -10,6 +10,8 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||||
refsGRPC "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc"
|
refsGRPC "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc"
|
||||||
session "github.com/nspcc-dev/neofs-api-go/v2/session/grpc"
|
session "github.com/nspcc-dev/neofs-api-go/v2/session/grpc"
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/v2/status"
|
||||||
|
statusGRPC "github.com/nspcc-dev/neofs-api-go/v2/status/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *CreateRequestBody) ToGRPCMessage() grpc.Message {
|
func (c *CreateRequestBody) ToGRPCMessage() grpc.Message {
|
||||||
|
@ -560,6 +562,7 @@ func (r *ResponseMetaHeader) ToGRPCMessage() grpc.Message {
|
||||||
m.SetEpoch(r.epoch)
|
m.SetEpoch(r.epoch)
|
||||||
m.SetTtl(r.ttl)
|
m.SetTtl(r.ttl)
|
||||||
m.SetOrigin(r.origin.ToGRPCMessage().(*session.ResponseMetaHeader))
|
m.SetOrigin(r.origin.ToGRPCMessage().(*session.ResponseMetaHeader))
|
||||||
|
m.SetStatus(r.status.ToGRPCMessage().(*statusGRPC.Status))
|
||||||
}
|
}
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
@ -601,6 +604,20 @@ func (r *ResponseMetaHeader) FromGRPCMessage(m grpc.Message) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
st := v.GetStatus()
|
||||||
|
if st == nil {
|
||||||
|
r.status = nil
|
||||||
|
} else {
|
||||||
|
if r.status == nil {
|
||||||
|
r.status = new(status.Status)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = r.status.FromGRPCMessage(st)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
r.xHeaders, err = XHeadersFromGRPC(v.GetXHeaders())
|
r.xHeaders, err = XHeadersFromGRPC(v.GetXHeaders())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -3,6 +3,7 @@ package session
|
||||||
import (
|
import (
|
||||||
acl "github.com/nspcc-dev/neofs-api-go/v2/acl/grpc"
|
acl "github.com/nspcc-dev/neofs-api-go/v2/acl/grpc"
|
||||||
refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc"
|
refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc"
|
||||||
|
status "github.com/nspcc-dev/neofs-api-go/v2/status/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetKey sets key to the X-Header.
|
// SetKey sets key to the X-Header.
|
||||||
|
@ -219,6 +220,13 @@ func (m *ResponseMetaHeader) SetOrigin(v *ResponseMetaHeader) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetStatus sets response status.
|
||||||
|
func (m *ResponseMetaHeader) SetStatus(v *status.Status) {
|
||||||
|
if m != nil {
|
||||||
|
m.Status = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// SetBodySignature sets signature of the request body.
|
// SetBodySignature sets signature of the request body.
|
||||||
func (m *RequestVerificationHeader) SetBodySignature(v *refs.Signature) {
|
func (m *RequestVerificationHeader) SetBodySignature(v *refs.Signature) {
|
||||||
if m != nil {
|
if m != nil {
|
||||||
|
|
|
@ -52,6 +52,7 @@ const (
|
||||||
respMetaHeaderTTLField = 3
|
respMetaHeaderTTLField = 3
|
||||||
respMetaHeaderXHeadersField = 4
|
respMetaHeaderXHeadersField = 4
|
||||||
respMetaHeaderOriginField = 5
|
respMetaHeaderOriginField = 5
|
||||||
|
respMetaHeaderStatusField = 6
|
||||||
|
|
||||||
respVerifHeaderBodySignatureField = 1
|
respVerifHeaderBodySignatureField = 1
|
||||||
respVerifHeaderMetaSignatureField = 2
|
respVerifHeaderMetaSignatureField = 2
|
||||||
|
@ -712,7 +713,14 @@ func (r *ResponseMetaHeader) StableMarshal(buf []byte) ([]byte, error) {
|
||||||
offset += n
|
offset += n
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = proto.NestedStructureMarshal(respMetaHeaderOriginField, buf[offset:], r.origin)
|
n, err = proto.NestedStructureMarshal(respMetaHeaderOriginField, buf[offset:], r.origin)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
offset += n
|
||||||
|
|
||||||
|
_, err = proto.NestedStructureMarshal(respMetaHeaderStatusField, buf[offset:], r.status)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -737,6 +745,7 @@ func (r *ResponseMetaHeader) StableSize() (size int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
size += proto.NestedStructureSize(respMetaHeaderOriginField, r.origin)
|
size += proto.NestedStructureSize(respMetaHeaderOriginField, r.origin)
|
||||||
|
size += proto.NestedStructureSize(respMetaHeaderStatusField, r.status)
|
||||||
|
|
||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
acltest "github.com/nspcc-dev/neofs-api-go/v2/acl/test"
|
acltest "github.com/nspcc-dev/neofs-api-go/v2/acl/test"
|
||||||
refstest "github.com/nspcc-dev/neofs-api-go/v2/refs/test"
|
refstest "github.com/nspcc-dev/neofs-api-go/v2/refs/test"
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
||||||
|
statustest "github.com/nspcc-dev/neofs-api-go/v2/status/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GenerateCreateRequestBody(empty bool) *session.CreateRequestBody {
|
func GenerateCreateRequestBody(empty bool) *session.CreateRequestBody {
|
||||||
|
@ -89,6 +90,7 @@ func generateResponseMetaHeader(empty, withOrigin bool) *session.ResponseMetaHea
|
||||||
|
|
||||||
m.SetXHeaders(GenerateXHeaders(empty))
|
m.SetXHeaders(GenerateXHeaders(empty))
|
||||||
m.SetVersion(refstest.GenerateVersion(empty))
|
m.SetVersion(refstest.GenerateVersion(empty))
|
||||||
|
m.SetStatus(statustest.Status(empty))
|
||||||
|
|
||||||
if withOrigin {
|
if withOrigin {
|
||||||
m.SetOrigin(generateResponseMetaHeader(empty, false))
|
m.SetOrigin(generateResponseMetaHeader(empty, false))
|
||||||
|
|
|
@ -3,6 +3,7 @@ package session
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/acl"
|
"github.com/nspcc-dev/neofs-api-go/v2/acl"
|
||||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/v2/status"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CreateRequestBody struct {
|
type CreateRequestBody struct {
|
||||||
|
@ -105,6 +106,8 @@ type ResponseMetaHeader struct {
|
||||||
xHeaders []*XHeader
|
xHeaders []*XHeader
|
||||||
|
|
||||||
origin *ResponseMetaHeader
|
origin *ResponseMetaHeader
|
||||||
|
|
||||||
|
status *status.Status
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -608,6 +611,39 @@ func (r *ResponseMetaHeader) SetOrigin(v *ResponseMetaHeader) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetStatus returns response status.
|
||||||
|
func (r *ResponseMetaHeader) GetStatus() *status.Status {
|
||||||
|
if r != nil {
|
||||||
|
return r.status
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatus sets response status.
|
||||||
|
func (r *ResponseMetaHeader) SetStatus(v *status.Status) {
|
||||||
|
if r != nil {
|
||||||
|
r.status = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatus sets status of the message which can carry ResponseMetaHeader.
|
||||||
|
//
|
||||||
|
// Sets status field on the "highest" level of meta headers.
|
||||||
|
// If meta header is missing in message, it is allocated.
|
||||||
|
func SetStatus(msg interface {
|
||||||
|
GetMetaHeader() *ResponseMetaHeader
|
||||||
|
SetMetaHeader(*ResponseMetaHeader)
|
||||||
|
}, st *status.Status) {
|
||||||
|
meta := msg.GetMetaHeader()
|
||||||
|
if meta == nil {
|
||||||
|
meta = new(ResponseMetaHeader)
|
||||||
|
msg.SetMetaHeader(meta)
|
||||||
|
}
|
||||||
|
|
||||||
|
meta.SetStatus(st)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *ObjectSessionContext) sessionTokenContext() {}
|
func (c *ObjectSessionContext) sessionTokenContext() {}
|
||||||
|
|
||||||
func (c *ObjectSessionContext) GetVerb() ObjectSessionVerb {
|
func (c *ObjectSessionContext) GetVerb() ObjectSessionVerb {
|
||||||
|
|
Loading…
Reference in New Issue