v2/service: Fill BearerToken uni-structure

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-08-17 13:04:21 +03:00 committed by Stanislav Bogatyrev
parent c55a9fa9bd
commit 18737e128c
2 changed files with 236 additions and 5 deletions

View file

@ -1,6 +1,8 @@
package service package service
import ( import (
"github.com/nspcc-dev/neofs-api-go/v2/acl"
"github.com/nspcc-dev/neofs-api-go/v2/refs"
service "github.com/nspcc-dev/neofs-api-go/v2/service/grpc" service "github.com/nspcc-dev/neofs-api-go/v2/service/grpc"
) )
@ -67,13 +69,39 @@ func SessionTokenFromGRPCMessage(m *service.SessionToken) *SessionToken {
} }
func BearerTokenToGRPCMessage(t *BearerToken) *service.BearerToken { func BearerTokenToGRPCMessage(t *BearerToken) *service.BearerToken {
// TODO: fill me if t == nil {
return nil return nil
}
m := new(service.BearerToken)
m.SetBody(
BearerTokenBodyToGRPCMessage(t.GetBody()),
)
m.SetSignature(
SignatureToGRPCMessage(t.GetSignature()),
)
return m
} }
func BearerTokenFromGRPCMessage(m *service.BearerToken) *BearerToken { func BearerTokenFromGRPCMessage(m *service.BearerToken) *BearerToken {
// TODO: fill me if m == nil {
return nil return nil
}
bt := new(BearerToken)
bt.SetBody(
BearerTokenBodyFromGRPCMessage(m.GetBody()),
)
bt.SetSignature(
SignatureFromGRPCMessage(m.GetSignature()),
)
return bt
} }
func RequestVerificationHeaderToGRPCMessage(r *RequestVerificationHeader) *service.RequestVerificationHeader { func RequestVerificationHeaderToGRPCMessage(r *RequestVerificationHeader) *service.RequestVerificationHeader {
@ -225,3 +253,75 @@ func SignatureFromGRPCMessage(m *service.Signature) *Signature {
return s return s
} }
func TokenLifetimeToGRPCMessage(tl *TokenLifetime) *service.TokenLifetime {
if tl == nil {
return nil
}
m := new(service.TokenLifetime)
m.SetExp(tl.GetExp())
m.SetNbf(tl.GetNbf())
m.SetIat(tl.GetIat())
return m
}
func TokenLifetimeFromGRPCMessage(m *service.TokenLifetime) *TokenLifetime {
if m == nil {
return nil
}
tl := new(TokenLifetime)
tl.SetExp(m.GetExp())
tl.SetNbf(m.GetNbf())
tl.SetIat(m.GetIat())
return tl
}
func BearerTokenBodyToGRPCMessage(v *BearerTokenBody) *service.BearerToken_Body {
if v == nil {
return nil
}
m := new(service.BearerToken_Body)
m.SetEaclTable(
acl.TableToGRPCMessage(v.GetEACL()),
)
m.SetOwnerId(
refs.OwnerIDToGRPCMessage(v.GetOwnerID()),
)
m.SetLifetime(
TokenLifetimeToGRPCMessage(v.GetLifetime()),
)
return m
}
func BearerTokenBodyFromGRPCMessage(m *service.BearerToken_Body) *BearerTokenBody {
if m == nil {
return nil
}
bt := new(BearerTokenBody)
bt.SetEACL(
acl.TableFromGRPCMessage(m.GetEaclTable()),
)
bt.SetOwnerID(
refs.OwnerIDFromGRPCMessage(m.GetOwnerId()),
)
bt.SetLifetime(
TokenLifetimeFromGRPCMessage(m.GetLifetime()),
)
return bt
}

View file

@ -1,5 +1,10 @@
package service package service
import (
"github.com/nspcc-dev/neofs-api-go/v2/acl"
"github.com/nspcc-dev/neofs-api-go/v2/refs"
)
type Signature struct { type Signature struct {
key, sign []byte key, sign []byte
} }
@ -12,12 +17,26 @@ type XHeader struct {
key, val string key, val string
} }
type TokenLifetime struct {
exp, nbf, iat uint64
}
type SessionToken struct { type SessionToken struct {
// TODO: fill me // TODO: fill me
} }
type BearerTokenBody struct {
eacl *acl.Table
ownerID *refs.OwnerID
lifetime *TokenLifetime
}
type BearerToken struct { type BearerToken struct {
// TODO: fill me body *BearerTokenBody
sig *Signature
} }
type RequestVerificationHeader struct { type RequestVerificationHeader struct {
@ -311,3 +330,115 @@ func (r *RequestMetaHeader) StableSize() int {
// TODO: do not use hack // TODO: do not use hack
return RequestMetaHeaderToGRPCMessage(r).Size() return RequestMetaHeaderToGRPCMessage(r).Size()
} }
func (tl *TokenLifetime) GetExp() uint64 {
if tl != nil {
return tl.exp
}
return 0
}
func (tl *TokenLifetime) SetExp(v uint64) {
if tl != nil {
tl.exp = v
}
}
func (tl *TokenLifetime) GetNbf() uint64 {
if tl != nil {
return tl.nbf
}
return 0
}
func (tl *TokenLifetime) SetNbf(v uint64) {
if tl != nil {
tl.nbf = v
}
}
func (tl *TokenLifetime) GetIat() uint64 {
if tl != nil {
return tl.iat
}
return 0
}
func (tl *TokenLifetime) SetIat(v uint64) {
if tl != nil {
tl.iat = v
}
}
func (bt *BearerTokenBody) GetEACL() *acl.Table {
if bt != nil {
return bt.eacl
}
return nil
}
func (bt *BearerTokenBody) SetEACL(v *acl.Table) {
if bt != nil {
bt.eacl = v
}
}
func (bt *BearerTokenBody) GetOwnerID() *refs.OwnerID {
if bt != nil {
return bt.ownerID
}
return nil
}
func (bt *BearerTokenBody) SetOwnerID(v *refs.OwnerID) {
if bt != nil {
bt.ownerID = v
}
}
func (bt *BearerTokenBody) GetLifetime() *TokenLifetime {
if bt != nil {
return bt.lifetime
}
return nil
}
func (bt *BearerTokenBody) SetLifetime(v *TokenLifetime) {
if bt != nil {
bt.lifetime = v
}
}
func (bt *BearerToken) GetBody() *BearerTokenBody {
if bt != nil {
return bt.body
}
return nil
}
func (bt *BearerToken) SetBody(v *BearerTokenBody) {
if bt != nil {
bt.body = v
}
}
func (bt *BearerToken) GetSignature() *Signature {
if bt != nil {
return bt.sig
}
return nil
}
func (bt *BearerToken) SetSignature(v *Signature) {
if bt != nil {
bt.sig = v
}
}