2020-08-17 14:01:53 +00:00
|
|
|
package session
|
|
|
|
|
|
|
|
import (
|
2020-08-20 10:32:02 +00:00
|
|
|
"fmt"
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/rpc/grpc"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/rpc/message"
|
2020-08-20 10:32:02 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/acl"
|
2021-03-12 12:57:23 +00:00
|
|
|
aclGRPC "github.com/nspcc-dev/neofs-api-go/v2/acl/grpc"
|
2020-08-17 14:01:53 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
2021-03-12 12:57:23 +00:00
|
|
|
refsGRPC "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc"
|
2020-08-17 14:01:53 +00:00
|
|
|
session "github.com/nspcc-dev/neofs-api-go/v2/session/grpc"
|
|
|
|
)
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (c *CreateRequestBody) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *session.CreateRequest_Body
|
2020-08-17 14:01:53 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if c != nil {
|
|
|
|
m = new(session.CreateRequest_Body)
|
2020-08-17 14:01:53 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetOwnerId(c.ownerID.ToGRPCMessage().(*refsGRPC.OwnerID))
|
|
|
|
m.SetExpiration(c.expiration)
|
|
|
|
}
|
2020-08-17 14:01:53 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (c *CreateRequestBody) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*session.CreateRequest_Body)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-17 14:01:53 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2020-08-17 14:01:53 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
ownerID := v.GetOwnerId()
|
|
|
|
if ownerID == nil {
|
|
|
|
c.ownerID = nil
|
|
|
|
} else {
|
|
|
|
if c.ownerID == nil {
|
|
|
|
c.ownerID = new(refs.OwnerID)
|
|
|
|
}
|
2020-08-17 14:01:53 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = c.ownerID.FromGRPCMessage(ownerID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-17 14:01:53 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
c.expiration = v.GetExpiration()
|
2020-08-17 14:01:53 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-08-17 14:01:53 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (c *CreateRequest) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *session.CreateRequest
|
2020-08-17 14:01:53 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if c != nil {
|
|
|
|
m = new(session.CreateRequest)
|
2020-08-17 14:01:53 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetBody(c.body.ToGRPCMessage().(*session.CreateRequest_Body))
|
|
|
|
c.RequestHeaders.ToMessage(m)
|
|
|
|
}
|
2020-08-17 14:01:53 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (c *CreateRequest) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*session.CreateRequest)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-17 14:01:53 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2020-08-17 14:01:53 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
body := v.GetBody()
|
|
|
|
if body == nil {
|
|
|
|
c.body = nil
|
|
|
|
} else {
|
|
|
|
if c.body == nil {
|
|
|
|
c.body = new(CreateRequestBody)
|
|
|
|
}
|
2020-08-17 14:01:53 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = c.body.FromGRPCMessage(body)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-17 14:01:53 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return c.RequestHeaders.FromMessage(v)
|
2020-08-17 14:01:53 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (c *CreateResponseBody) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *session.CreateResponse_Body
|
2020-08-17 14:01:53 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if c != nil {
|
|
|
|
m = new(session.CreateResponse_Body)
|
2020-08-17 14:01:53 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetSessionKey(c.sessionKey)
|
|
|
|
m.SetId(c.id)
|
|
|
|
}
|
2020-08-17 14:01:53 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (c *CreateResponseBody) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*session.CreateResponse_Body)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-17 14:01:53 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
c.sessionKey = v.GetSessionKey()
|
|
|
|
c.id = v.GetId()
|
2020-08-17 14:01:53 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2020-08-17 14:01:53 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (c *CreateResponse) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *session.CreateResponse
|
2020-08-17 14:01:53 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if c != nil {
|
|
|
|
m = new(session.CreateResponse)
|
2020-08-17 14:01:53 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetBody(c.body.ToGRPCMessage().(*session.CreateResponse_Body))
|
|
|
|
c.ResponseHeaders.ToMessage(m)
|
|
|
|
}
|
2020-08-17 14:01:53 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (c *CreateResponse) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*session.CreateResponse)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-17 14:01:53 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2020-08-17 14:01:53 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
body := v.GetBody()
|
|
|
|
if body == nil {
|
|
|
|
c.body = nil
|
|
|
|
} else {
|
|
|
|
if c.body == nil {
|
|
|
|
c.body = new(CreateResponseBody)
|
|
|
|
}
|
2020-08-17 14:01:53 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = c.body.FromGRPCMessage(body)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return c.ResponseHeaders.FromMessage(v)
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (l *TokenLifetime) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *session.SessionToken_Body_TokenLifetime
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if l != nil {
|
|
|
|
m = new(session.SessionToken_Body_TokenLifetime)
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetExp(l.exp)
|
|
|
|
m.SetIat(l.iat)
|
|
|
|
m.SetNbf(l.nbf)
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (l *TokenLifetime) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*session.SessionToken_Body_TokenLifetime)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
l.exp = v.GetExp()
|
|
|
|
l.iat = v.GetIat()
|
|
|
|
l.nbf = v.GetNbf()
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (x *XHeader) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *session.XHeader
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if x != nil {
|
|
|
|
m = new(session.XHeader)
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetKey(x.key)
|
|
|
|
m.SetValue(x.val)
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (x *XHeader) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*session.XHeader)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
x.key = v.GetKey()
|
|
|
|
x.val = v.GetValue()
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func XHeadersToGRPC(xs []*XHeader) (res []*session.XHeader) {
|
|
|
|
if xs != nil {
|
|
|
|
res = make([]*session.XHeader, 0, len(xs))
|
|
|
|
|
|
|
|
for i := range xs {
|
|
|
|
res = append(res, xs[i].ToGRPCMessage().(*session.XHeader))
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func XHeadersFromGRPC(xs []*session.XHeader) (res []*XHeader, err error) {
|
|
|
|
if xs != nil {
|
|
|
|
res = make([]*XHeader, 0, len(xs))
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
for i := range xs {
|
|
|
|
var x *XHeader
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if xs[i] != nil {
|
|
|
|
x = new(XHeader)
|
|
|
|
|
|
|
|
err = x.FromGRPCMessage(xs[i])
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
res = append(res, x)
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (t *SessionToken) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *session.SessionToken
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if t != nil {
|
|
|
|
m = new(session.SessionToken)
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetBody(t.body.ToGRPCMessage().(*session.SessionToken_Body))
|
|
|
|
m.SetSignature(t.sig.ToGRPCMessage().(*refsGRPC.Signature))
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (t *SessionToken) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*session.SessionToken)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
body := v.GetBody()
|
|
|
|
if body == nil {
|
|
|
|
t.body = nil
|
|
|
|
} else {
|
|
|
|
if t.body == nil {
|
|
|
|
t.body = new(SessionTokenBody)
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = t.body.FromGRPCMessage(body)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
sig := v.GetSignature()
|
|
|
|
if sig == nil {
|
|
|
|
t.sig = nil
|
|
|
|
} else {
|
|
|
|
if t.sig == nil {
|
|
|
|
t.sig = new(refs.Signature)
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = t.sig.FromGRPCMessage(sig)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (r *RequestVerificationHeader) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *session.RequestVerificationHeader
|
|
|
|
|
|
|
|
if r != nil {
|
|
|
|
m = new(session.RequestVerificationHeader)
|
|
|
|
|
|
|
|
m.SetBodySignature(r.bodySig.ToGRPCMessage().(*refsGRPC.Signature))
|
|
|
|
m.SetMetaSignature(r.metaSig.ToGRPCMessage().(*refsGRPC.Signature))
|
|
|
|
m.SetOriginSignature(r.originSig.ToGRPCMessage().(*refsGRPC.Signature))
|
|
|
|
m.SetOrigin(r.origin.ToGRPCMessage().(*session.RequestVerificationHeader))
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return m
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (r *RequestVerificationHeader) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*session.RequestVerificationHeader)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
originSig := v.GetOriginSignature()
|
|
|
|
if originSig == nil {
|
|
|
|
r.originSig = nil
|
|
|
|
} else {
|
|
|
|
if r.originSig == nil {
|
|
|
|
r.originSig = new(refs.Signature)
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = r.originSig.FromGRPCMessage(originSig)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
metaSig := v.GetMetaSignature()
|
|
|
|
if metaSig == nil {
|
|
|
|
r.metaSig = nil
|
|
|
|
} else {
|
|
|
|
if r.metaSig == nil {
|
|
|
|
r.metaSig = new(refs.Signature)
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = r.metaSig.FromGRPCMessage(metaSig)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
bodySig := v.GetBodySignature()
|
|
|
|
if bodySig == nil {
|
|
|
|
r.bodySig = nil
|
|
|
|
} else {
|
|
|
|
if r.bodySig == nil {
|
|
|
|
r.bodySig = new(refs.Signature)
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = r.bodySig.FromGRPCMessage(bodySig)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
origin := v.GetOrigin()
|
|
|
|
if origin == nil {
|
|
|
|
r.origin = nil
|
|
|
|
} else {
|
|
|
|
if r.origin == nil {
|
|
|
|
r.origin = new(RequestVerificationHeader)
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = r.origin.FromGRPCMessage(origin)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (r *RequestMetaHeader) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *session.RequestMetaHeader
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if r != nil {
|
|
|
|
m = new(session.RequestMetaHeader)
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetVersion(r.version.ToGRPCMessage().(*refsGRPC.Version))
|
|
|
|
m.SetSessionToken(r.sessionToken.ToGRPCMessage().(*session.SessionToken))
|
|
|
|
m.SetBearerToken(r.bearerToken.ToGRPCMessage().(*aclGRPC.BearerToken))
|
|
|
|
m.SetXHeaders(XHeadersToGRPC(r.xHeaders))
|
|
|
|
m.SetEpoch(r.epoch)
|
|
|
|
m.SetTtl(r.ttl)
|
|
|
|
m.SetOrigin(r.origin.ToGRPCMessage().(*session.RequestMetaHeader))
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (r *RequestMetaHeader) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*session.RequestMetaHeader)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
version := v.GetVersion()
|
|
|
|
if version == nil {
|
|
|
|
r.version = nil
|
|
|
|
} else {
|
|
|
|
if r.version == nil {
|
|
|
|
r.version = new(refs.Version)
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = r.version.FromGRPCMessage(version)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
sessionToken := v.GetSessionToken()
|
|
|
|
if sessionToken == nil {
|
|
|
|
r.sessionToken = nil
|
|
|
|
} else {
|
|
|
|
if r.sessionToken == nil {
|
|
|
|
r.sessionToken = new(SessionToken)
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = r.sessionToken.FromGRPCMessage(sessionToken)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
bearerToken := v.GetBearerToken()
|
|
|
|
if bearerToken == nil {
|
|
|
|
r.bearerToken = nil
|
|
|
|
} else {
|
|
|
|
if r.bearerToken == nil {
|
|
|
|
r.bearerToken = new(acl.BearerToken)
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = r.bearerToken.FromGRPCMessage(bearerToken)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
origin := v.GetOrigin()
|
|
|
|
if origin == nil {
|
|
|
|
r.origin = nil
|
|
|
|
} else {
|
|
|
|
if r.origin == nil {
|
|
|
|
r.origin = new(RequestMetaHeader)
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = r.origin.FromGRPCMessage(origin)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
r.xHeaders, err = XHeadersFromGRPC(v.GetXHeaders())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
r.epoch = v.GetEpoch()
|
|
|
|
r.ttl = v.GetTtl()
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (r *ResponseVerificationHeader) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *session.ResponseVerificationHeader
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if r != nil {
|
|
|
|
m = new(session.ResponseVerificationHeader)
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetBodySignature(r.bodySig.ToGRPCMessage().(*refsGRPC.Signature))
|
|
|
|
m.SetMetaSignature(r.metaSig.ToGRPCMessage().(*refsGRPC.Signature))
|
|
|
|
m.SetOriginSignature(r.originSig.ToGRPCMessage().(*refsGRPC.Signature))
|
|
|
|
m.SetOrigin(r.origin.ToGRPCMessage().(*session.ResponseVerificationHeader))
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (r *ResponseVerificationHeader) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*session.ResponseVerificationHeader)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
originSig := v.GetOriginSignature()
|
|
|
|
if originSig == nil {
|
|
|
|
r.originSig = nil
|
|
|
|
} else {
|
|
|
|
if r.originSig == nil {
|
|
|
|
r.originSig = new(refs.Signature)
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = r.originSig.FromGRPCMessage(originSig)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
metaSig := v.GetMetaSignature()
|
|
|
|
if metaSig == nil {
|
|
|
|
r.metaSig = nil
|
|
|
|
} else {
|
|
|
|
if r.metaSig == nil {
|
|
|
|
r.metaSig = new(refs.Signature)
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = r.metaSig.FromGRPCMessage(metaSig)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
bodySig := v.GetBodySignature()
|
|
|
|
if bodySig == nil {
|
|
|
|
r.bodySig = nil
|
|
|
|
} else {
|
|
|
|
if r.bodySig == nil {
|
|
|
|
r.bodySig = new(refs.Signature)
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = r.bodySig.FromGRPCMessage(bodySig)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
origin := v.GetOrigin()
|
|
|
|
if origin == nil {
|
|
|
|
r.origin = nil
|
|
|
|
} else {
|
|
|
|
if r.origin == nil {
|
|
|
|
r.origin = new(ResponseVerificationHeader)
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = r.origin.FromGRPCMessage(origin)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (r *ResponseMetaHeader) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *session.ResponseMetaHeader
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if r != nil {
|
|
|
|
m = new(session.ResponseMetaHeader)
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetVersion(r.version.ToGRPCMessage().(*refsGRPC.Version))
|
|
|
|
m.SetXHeaders(XHeadersToGRPC(r.xHeaders))
|
|
|
|
m.SetEpoch(r.epoch)
|
|
|
|
m.SetTtl(r.ttl)
|
|
|
|
m.SetOrigin(r.origin.ToGRPCMessage().(*session.ResponseMetaHeader))
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (r *ResponseMetaHeader) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*session.ResponseMetaHeader)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
version := v.GetVersion()
|
|
|
|
if version == nil {
|
|
|
|
r.version = nil
|
|
|
|
} else {
|
|
|
|
if r.version == nil {
|
|
|
|
r.version = new(refs.Version)
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = r.version.FromGRPCMessage(version)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
origin := v.GetOrigin()
|
|
|
|
if origin == nil {
|
|
|
|
r.origin = nil
|
|
|
|
} else {
|
|
|
|
if r.origin == nil {
|
|
|
|
r.origin = new(ResponseMetaHeader)
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = r.origin.FromGRPCMessage(origin)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
r.xHeaders, err = XHeadersFromGRPC(v.GetXHeaders())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
r.epoch = v.GetEpoch()
|
|
|
|
r.ttl = v.GetTtl()
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ObjectSessionVerbToGRPCField(v ObjectSessionVerb) session.ObjectSessionContext_Verb {
|
|
|
|
switch v {
|
|
|
|
case ObjectVerbPut:
|
|
|
|
return session.ObjectSessionContext_PUT
|
|
|
|
case ObjectVerbGet:
|
|
|
|
return session.ObjectSessionContext_GET
|
|
|
|
case ObjectVerbHead:
|
|
|
|
return session.ObjectSessionContext_HEAD
|
|
|
|
case ObjectVerbSearch:
|
|
|
|
return session.ObjectSessionContext_SEARCH
|
|
|
|
case ObjectVerbDelete:
|
|
|
|
return session.ObjectSessionContext_DELETE
|
|
|
|
case ObjectVerbRange:
|
|
|
|
return session.ObjectSessionContext_RANGE
|
|
|
|
case ObjectVerbRangeHash:
|
|
|
|
return session.ObjectSessionContext_RANGEHASH
|
|
|
|
default:
|
|
|
|
return session.ObjectSessionContext_VERB_UNSPECIFIED
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ObjectSessionVerbFromGRPCField(v session.ObjectSessionContext_Verb) ObjectSessionVerb {
|
|
|
|
switch v {
|
|
|
|
case session.ObjectSessionContext_PUT:
|
|
|
|
return ObjectVerbPut
|
|
|
|
case session.ObjectSessionContext_GET:
|
|
|
|
return ObjectVerbGet
|
|
|
|
case session.ObjectSessionContext_HEAD:
|
|
|
|
return ObjectVerbHead
|
|
|
|
case session.ObjectSessionContext_SEARCH:
|
|
|
|
return ObjectVerbSearch
|
|
|
|
case session.ObjectSessionContext_DELETE:
|
|
|
|
return ObjectVerbDelete
|
|
|
|
case session.ObjectSessionContext_RANGE:
|
|
|
|
return ObjectVerbRange
|
|
|
|
case session.ObjectSessionContext_RANGEHASH:
|
|
|
|
return ObjectVerbRangeHash
|
|
|
|
default:
|
|
|
|
return ObjectVerbUnknown
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (c *ObjectSessionContext) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *session.ObjectSessionContext
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if c != nil {
|
|
|
|
m = new(session.ObjectSessionContext)
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetVerb(ObjectSessionVerbToGRPCField(c.verb))
|
|
|
|
m.SetAddress(c.addr.ToGRPCMessage().(*refsGRPC.Address))
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (c *ObjectSessionContext) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*session.ObjectSessionContext)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
addr := v.GetAddress()
|
|
|
|
if addr == nil {
|
|
|
|
c.addr = nil
|
|
|
|
} else {
|
|
|
|
if c.addr == nil {
|
|
|
|
c.addr = new(refs.Address)
|
|
|
|
}
|
2020-08-17 14:01:53 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = c.addr.FromGRPCMessage(addr)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
c.verb = ObjectSessionVerbFromGRPCField(v.GetVerb())
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (t *SessionTokenBody) ToGRPCMessage() grpc.Message {
|
|
|
|
var m *session.SessionToken_Body
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if t != nil {
|
|
|
|
m = new(session.SessionToken_Body)
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
switch typ := t.ctx.(type) {
|
|
|
|
default:
|
|
|
|
panic(fmt.Sprintf("unknown session context %T", typ))
|
|
|
|
case nil:
|
|
|
|
m.Context = nil
|
|
|
|
case *ObjectSessionContext:
|
|
|
|
m.SetObjectSessionContext(typ.ToGRPCMessage().(*session.ObjectSessionContext))
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetOwnerId(t.ownerID.ToGRPCMessage().(*refsGRPC.OwnerID))
|
|
|
|
m.SetId(t.id)
|
|
|
|
m.SetSessionKey(t.sessionKey)
|
|
|
|
m.SetLifetime(t.lifetime.ToGRPCMessage().(*session.SessionToken_Body_TokenLifetime))
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func (t *SessionTokenBody) FromGRPCMessage(m grpc.Message) error {
|
|
|
|
v, ok := m.(*session.SessionToken_Body)
|
|
|
|
if !ok {
|
|
|
|
return message.NewUnexpectedMessageType(m, v)
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
var err error
|
|
|
|
|
|
|
|
t.ctx = nil
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
switch val := v.GetContext().(type) {
|
|
|
|
default:
|
2021-05-17 12:56:17 +00:00
|
|
|
err = fmt.Errorf("unknown session context %T", val)
|
2020-08-20 10:32:02 +00:00
|
|
|
case nil:
|
|
|
|
case *session.SessionToken_Body_Object:
|
2021-03-12 12:57:23 +00:00
|
|
|
ctx, ok := t.ctx.(*ObjectSessionContext)
|
|
|
|
if !ok {
|
|
|
|
ctx = new(ObjectSessionContext)
|
|
|
|
t.ctx = ctx
|
|
|
|
}
|
|
|
|
|
|
|
|
err = ctx.FromGRPCMessage(val.Object)
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
ownerID := v.GetOwnerId()
|
|
|
|
if ownerID == nil {
|
|
|
|
t.ownerID = nil
|
|
|
|
} else {
|
|
|
|
if t.ownerID == nil {
|
|
|
|
t.ownerID = new(refs.OwnerID)
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
err = t.ownerID.FromGRPCMessage(ownerID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
lifetime := v.GetLifetime()
|
|
|
|
if lifetime == nil {
|
|
|
|
t.lifetime = nil
|
|
|
|
} else {
|
|
|
|
if t.lifetime == nil {
|
|
|
|
t.lifetime = new(TokenLifetime)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = t.lifetime.FromGRPCMessage(lifetime)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
t.id = v.GetId()
|
|
|
|
t.sessionKey = v.GetSessionKey()
|
2020-08-20 10:32:02 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
return nil
|
2020-08-20 10:32:02 +00:00
|
|
|
}
|