v2/session: Implement session uni-structures

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-08-17 17:01:53 +03:00 committed by Stanislav Bogatyrev
parent 57dcf01f6b
commit e5faf622df
2 changed files with 307 additions and 0 deletions

133
v2/session/convert.go Normal file
View file

@ -0,0 +1,133 @@
package session
import (
"github.com/nspcc-dev/neofs-api-go/v2/refs"
"github.com/nspcc-dev/neofs-api-go/v2/service"
session "github.com/nspcc-dev/neofs-api-go/v2/session/grpc"
)
func CreateRequestBodyToGRPCMessage(c *CreateRequestBody) *session.CreateRequest_Body {
if c == nil {
return nil
}
m := new(session.CreateRequest_Body)
m.SetOwnerId(
refs.OwnerIDToGRPCMessage(c.GetOwnerID()),
)
m.SetLifetime(
service.TokenLifetimeToGRPCMessage(c.GetLifetime()),
)
return m
}
func CreateRequestBodyFromGRPCMessage(m *session.CreateRequest_Body) *CreateRequestBody {
if m == nil {
return nil
}
c := new(CreateRequestBody)
c.SetOwnerID(
refs.OwnerIDFromGRPCMessage(m.GetOwnerId()),
)
c.SetLifetime(
service.TokenLifetimeFromGRPCMessage(m.GetLifetime()),
)
return c
}
func CreateRequestToGRPCMessage(c *CreateRequest) *session.CreateRequest {
if c == nil {
return nil
}
m := new(session.CreateRequest)
m.SetBody(
CreateRequestBodyToGRPCMessage(c.GetBody()),
)
service.RequestHeadersToGRPC(c, m)
return m
}
func CreateRequestFromGRPCMessage(m *session.CreateRequest) *CreateRequest {
if m == nil {
return nil
}
c := new(CreateRequest)
c.SetBody(
CreateRequestBodyFromGRPCMessage(m.GetBody()),
)
service.RequestHeadersFromGRPC(m, c)
return c
}
func CreateResponseBodyToGRPCMessage(c *CreateResponseBody) *session.CreateResponse_Body {
if c == nil {
return nil
}
m := new(session.CreateResponse_Body)
m.SetId(c.GetID())
m.SetSessionKey(c.GetSessionKey())
return m
}
func CreateResponseBodyFromGRPCMessage(m *session.CreateResponse_Body) *CreateResponseBody {
if m == nil {
return nil
}
c := new(CreateResponseBody)
c.SetID(m.GetId())
c.SetSessionKey(m.GetSessionKey())
return c
}
func CreateResponseToGRPCMessage(c *CreateResponse) *session.CreateResponse {
if c == nil {
return nil
}
m := new(session.CreateResponse)
m.SetBody(
CreateResponseBodyToGRPCMessage(c.GetBody()),
)
service.ResponseHeadersToGRPC(c, m)
return m
}
func CreateResponseFromGRPCMessage(m *session.CreateResponse) *CreateResponse {
if m == nil {
return nil
}
c := new(CreateResponse)
c.SetBody(
CreateResponseBodyFromGRPCMessage(m.GetBody()),
)
service.ResponseHeadersFromGRPC(m, c)
return c
}

174
v2/session/types.go Normal file
View file

@ -0,0 +1,174 @@
package session
import (
"github.com/nspcc-dev/neofs-api-go/v2/refs"
"github.com/nspcc-dev/neofs-api-go/v2/service"
)
type CreateRequestBody struct {
ownerID *refs.OwnerID
lifetime *service.TokenLifetime
}
type CreateRequest struct {
body *CreateRequestBody
metaHeader *service.RequestMetaHeader
verifyHeader *service.RequestVerificationHeader
}
type CreateResponseBody struct {
id []byte
sessionKey []byte
}
type CreateResponse struct {
body *CreateResponseBody
metaHeader *service.ResponseMetaHeader
verifyHeader *service.ResponseVerificationHeader
}
func (c *CreateRequestBody) GetOwnerID() *refs.OwnerID {
if c != nil {
return c.ownerID
}
return nil
}
func (c *CreateRequestBody) SetOwnerID(v *refs.OwnerID) {
if c != nil {
c.ownerID = v
}
}
func (c *CreateRequestBody) GetLifetime() *service.TokenLifetime {
if c != nil {
return c.lifetime
}
return nil
}
func (c *CreateRequestBody) SetLifetime(v *service.TokenLifetime) {
if c != nil {
c.lifetime = v
}
}
func (c *CreateRequest) GetBody() *CreateRequestBody {
if c != nil {
return c.body
}
return nil
}
func (c *CreateRequest) SetBody(v *CreateRequestBody) {
if c != nil {
c.body = v
}
}
func (c *CreateRequest) GetMetaHeader() *service.RequestMetaHeader {
if c != nil {
return c.metaHeader
}
return nil
}
func (c *CreateRequest) SetMetaHeader(v *service.RequestMetaHeader) {
if c != nil {
c.metaHeader = v
}
}
func (c *CreateRequest) GetVerificationHeader() *service.RequestVerificationHeader {
if c != nil {
return c.verifyHeader
}
return nil
}
func (c *CreateRequest) SetVerificationHeader(v *service.RequestVerificationHeader) {
if c != nil {
c.verifyHeader = v
}
}
func (c *CreateResponseBody) GetID() []byte {
if c != nil {
return c.id
}
return nil
}
func (c *CreateResponseBody) SetID(v []byte) {
if c != nil {
c.id = v
}
}
func (c *CreateResponseBody) GetSessionKey() []byte {
if c != nil {
return c.sessionKey
}
return nil
}
func (c *CreateResponseBody) SetSessionKey(v []byte) {
if c != nil {
c.sessionKey = v
}
}
func (c *CreateResponse) GetBody() *CreateResponseBody {
if c != nil {
return c.body
}
return nil
}
func (c *CreateResponse) SetBody(v *CreateResponseBody) {
if c != nil {
c.body = v
}
}
func (c *CreateResponse) GetMetaHeader() *service.ResponseMetaHeader {
if c != nil {
return c.metaHeader
}
return nil
}
func (c *CreateResponse) SetMetaHeader(v *service.ResponseMetaHeader) {
if c != nil {
c.metaHeader = v
}
}
func (c *CreateResponse) GetVerificationHeader() *service.ResponseVerificationHeader {
if c != nil {
return c.verifyHeader
}
return nil
}
func (c *CreateResponse) SetVerificationHeader(v *service.ResponseVerificationHeader) {
if c != nil {
c.verifyHeader = v
}
}