Some checks failed
DCO action / DCO (pull_request) Successful in 48s
Tests and linters / Tests (1.19) (pull_request) Failing after 59s
Tests and linters / Tests with -race (pull_request) Successful in 1m31s
Tests and linters / Tests (1.20) (pull_request) Failing after 5m52s
Tests and linters / Lint (pull_request) Successful in 7m3s
* Use protowire.AppendTag to encode a tag and append it * Use protowire.AppendVarint to append numeric data * Use protowire.AppendBytes and protowire.AppendString Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
560 lines
14 KiB
Go
560 lines
14 KiB
Go
package session
|
|
|
|
import (
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
|
|
session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
|
|
goproto "google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
const (
|
|
createReqBodyOwnerField = 1
|
|
createReqBodyExpirationField = 2
|
|
|
|
createRespBodyIDField = 1
|
|
createRespBodyKeyField = 2
|
|
|
|
xheaderKeyField = 1
|
|
xheaderValueField = 2
|
|
|
|
lifetimeExpirationField = 1
|
|
lifetimeNotValidBeforeField = 2
|
|
lifetimeIssuedAtField = 3
|
|
|
|
objectCtxVerbField = 1
|
|
objectCtxTargetField = 2
|
|
|
|
sessionTokenBodyIDField = 1
|
|
sessionTokenBodyOwnerField = 2
|
|
sessionTokenBodyLifetimeField = 3
|
|
sessionTokenBodyKeyField = 4
|
|
sessionTokenBodyObjectCtxField = 5
|
|
sessionTokenBodyCnrCtxField = 6
|
|
|
|
sessionTokenBodyField = 1
|
|
sessionTokenSignatureField = 2
|
|
|
|
reqMetaHeaderVersionField = 1
|
|
reqMetaHeaderEpochField = 2
|
|
reqMetaHeaderTTLField = 3
|
|
reqMetaHeaderXHeadersField = 4
|
|
reqMetaHeaderSessionTokenField = 5
|
|
reqMetaHeaderBearerTokenField = 6
|
|
reqMetaHeaderOriginField = 7
|
|
reqMetaHeaderNetMagicField = 8
|
|
|
|
reqVerifHeaderBodySignatureField = 1
|
|
reqVerifHeaderMetaSignatureField = 2
|
|
reqVerifHeaderOriginSignatureField = 3
|
|
reqVerifHeaderOriginField = 4
|
|
|
|
respMetaHeaderVersionField = 1
|
|
respMetaHeaderEpochField = 2
|
|
respMetaHeaderTTLField = 3
|
|
respMetaHeaderXHeadersField = 4
|
|
respMetaHeaderOriginField = 5
|
|
respMetaHeaderStatusField = 6
|
|
|
|
respVerifHeaderBodySignatureField = 1
|
|
respVerifHeaderMetaSignatureField = 2
|
|
respVerifHeaderOriginSignatureField = 3
|
|
respVerifHeaderOriginField = 4
|
|
)
|
|
|
|
func (c *CreateRequestBody) StableMarshal(buf []byte) []byte {
|
|
if c == nil {
|
|
return []byte{}
|
|
}
|
|
|
|
if buf == nil {
|
|
buf = make([]byte, 0, c.StableSize())
|
|
}
|
|
|
|
buf = proto.NestedStructureMarshal(createReqBodyOwnerField, buf, c.ownerID)
|
|
buf = proto.UInt64Marshal(createReqBodyExpirationField, buf, c.expiration)
|
|
|
|
return buf
|
|
}
|
|
|
|
func (c *CreateRequestBody) StableSize() (size int) {
|
|
if c == nil {
|
|
return 0
|
|
}
|
|
|
|
size += proto.NestedStructureSize(createReqBodyOwnerField, c.ownerID)
|
|
size += proto.UInt64Size(createReqBodyExpirationField, c.expiration)
|
|
|
|
return size
|
|
}
|
|
|
|
func (c *CreateRequestBody) Unmarshal(data []byte) error {
|
|
return message.Unmarshal(c, data, new(session.CreateRequest_Body))
|
|
}
|
|
|
|
func (c *CreateResponseBody) StableMarshal(buf []byte) []byte {
|
|
if c == nil {
|
|
return []byte{}
|
|
}
|
|
|
|
if buf == nil {
|
|
buf = make([]byte, 0, c.StableSize())
|
|
}
|
|
|
|
buf = proto.BytesMarshal(createRespBodyIDField, buf, c.id)
|
|
buf = proto.BytesMarshal(createRespBodyKeyField, buf, c.sessionKey)
|
|
|
|
return buf
|
|
}
|
|
|
|
func (c *CreateResponseBody) StableSize() (size int) {
|
|
if c == nil {
|
|
return 0
|
|
}
|
|
|
|
size += proto.BytesSize(createRespBodyIDField, c.id)
|
|
size += proto.BytesSize(createRespBodyKeyField, c.sessionKey)
|
|
|
|
return size
|
|
}
|
|
|
|
func (c *CreateResponseBody) Unmarshal(data []byte) error {
|
|
return message.Unmarshal(c, data, new(session.CreateResponse_Body))
|
|
}
|
|
|
|
func (x *XHeader) StableMarshal(buf []byte) []byte {
|
|
if x == nil {
|
|
return []byte{}
|
|
}
|
|
|
|
if buf == nil {
|
|
buf = make([]byte, 0, x.StableSize())
|
|
}
|
|
|
|
buf = proto.StringMarshal(xheaderKeyField, buf, x.key)
|
|
buf = proto.StringMarshal(xheaderValueField, buf, x.val)
|
|
|
|
return buf
|
|
}
|
|
|
|
func (x *XHeader) StableSize() (size int) {
|
|
if x == nil {
|
|
return 0
|
|
}
|
|
|
|
size += proto.StringSize(xheaderKeyField, x.key)
|
|
size += proto.StringSize(xheaderValueField, x.val)
|
|
|
|
return size
|
|
}
|
|
|
|
func (x *XHeader) Unmarshal(data []byte) error {
|
|
m := new(session.XHeader)
|
|
if err := goproto.Unmarshal(data, m); err != nil {
|
|
return err
|
|
}
|
|
|
|
return x.FromGRPCMessage(m)
|
|
}
|
|
|
|
func (l *TokenLifetime) StableMarshal(buf []byte) []byte {
|
|
if l == nil {
|
|
return []byte{}
|
|
}
|
|
|
|
if buf == nil {
|
|
buf = make([]byte, 0, l.StableSize())
|
|
}
|
|
|
|
buf = proto.UInt64Marshal(lifetimeExpirationField, buf, l.exp)
|
|
buf = proto.UInt64Marshal(lifetimeNotValidBeforeField, buf, l.nbf)
|
|
buf = proto.UInt64Marshal(lifetimeIssuedAtField, buf, l.iat)
|
|
|
|
return buf
|
|
}
|
|
|
|
func (l *TokenLifetime) StableSize() (size int) {
|
|
if l == nil {
|
|
return 0
|
|
}
|
|
|
|
size += proto.UInt64Size(lifetimeExpirationField, l.exp)
|
|
size += proto.UInt64Size(lifetimeNotValidBeforeField, l.nbf)
|
|
size += proto.UInt64Size(lifetimeIssuedAtField, l.iat)
|
|
|
|
return size
|
|
}
|
|
|
|
func (l *TokenLifetime) Unmarshal(data []byte) error {
|
|
m := new(session.SessionToken_Body_TokenLifetime)
|
|
if err := goproto.Unmarshal(data, m); err != nil {
|
|
return err
|
|
}
|
|
|
|
return l.FromGRPCMessage(m)
|
|
}
|
|
|
|
func (c *ObjectSessionContext) StableMarshal(buf []byte) []byte {
|
|
if c == nil {
|
|
return []byte{}
|
|
}
|
|
|
|
if buf == nil {
|
|
buf = make([]byte, 0, c.StableSize())
|
|
}
|
|
|
|
buf = proto.EnumMarshal(objectCtxVerbField, buf, int32(c.verb))
|
|
buf = proto.NestedStructureMarshal(objectCtxTargetField, buf, objectSessionContextTarget{
|
|
cnr: c.cnr,
|
|
objs: c.objs,
|
|
})
|
|
|
|
return buf
|
|
}
|
|
|
|
func (c *ObjectSessionContext) StableSize() (size int) {
|
|
if c == nil {
|
|
return 0
|
|
}
|
|
|
|
size += proto.EnumSize(objectCtxVerbField, int32(c.verb))
|
|
size += proto.NestedStructureSize(objectCtxTargetField, objectSessionContextTarget{
|
|
cnr: c.cnr,
|
|
objs: c.objs,
|
|
})
|
|
|
|
return size
|
|
}
|
|
|
|
func (c *ObjectSessionContext) Unmarshal(data []byte) error {
|
|
m := new(session.ObjectSessionContext)
|
|
if err := goproto.Unmarshal(data, m); err != nil {
|
|
return err
|
|
}
|
|
|
|
return c.FromGRPCMessage(m)
|
|
}
|
|
|
|
const (
|
|
_ = iota
|
|
cnrCtxVerbFNum
|
|
cnrCtxWildcardFNum
|
|
cnrCtxCidFNum
|
|
)
|
|
|
|
func (x *ContainerSessionContext) StableMarshal(buf []byte) []byte {
|
|
if x == nil {
|
|
return []byte{}
|
|
}
|
|
|
|
if buf == nil {
|
|
buf = make([]byte, 0, x.StableSize())
|
|
}
|
|
|
|
buf = proto.EnumMarshal(cnrCtxVerbFNum, buf, int32(ContainerSessionVerbToGRPCField(x.verb)))
|
|
buf = proto.BoolMarshal(cnrCtxWildcardFNum, buf, x.wildcard)
|
|
buf = proto.NestedStructureMarshal(cnrCtxCidFNum, buf, x.cid)
|
|
|
|
return buf
|
|
}
|
|
|
|
func (x *ContainerSessionContext) StableSize() (size int) {
|
|
if x == nil {
|
|
return 0
|
|
}
|
|
|
|
size += proto.EnumSize(cnrCtxVerbFNum, int32(ContainerSessionVerbToGRPCField(x.verb)))
|
|
size += proto.BoolSize(cnrCtxWildcardFNum, x.wildcard)
|
|
size += proto.NestedStructureSize(cnrCtxCidFNum, x.cid)
|
|
|
|
return size
|
|
}
|
|
|
|
func (x *ContainerSessionContext) Unmarshal(data []byte) error {
|
|
return message.Unmarshal(x, data, new(session.ContainerSessionContext))
|
|
}
|
|
|
|
func (t *TokenBody) StableMarshal(buf []byte) []byte {
|
|
if t == nil {
|
|
return []byte{}
|
|
}
|
|
|
|
if buf == nil {
|
|
buf = make([]byte, 0, t.StableSize())
|
|
}
|
|
|
|
buf = proto.BytesMarshal(sessionTokenBodyIDField, buf, t.id)
|
|
buf = proto.NestedStructureMarshal(sessionTokenBodyOwnerField, buf, t.ownerID)
|
|
buf = proto.NestedStructureMarshal(sessionTokenBodyLifetimeField, buf, t.lifetime)
|
|
buf = proto.BytesMarshal(sessionTokenBodyKeyField, buf, t.sessionKey)
|
|
|
|
if t.ctx != nil {
|
|
switch v := t.ctx.(type) {
|
|
case *ObjectSessionContext:
|
|
buf = proto.NestedStructureMarshal(sessionTokenBodyObjectCtxField, buf, v)
|
|
case *ContainerSessionContext:
|
|
buf = proto.NestedStructureMarshal(sessionTokenBodyCnrCtxField, buf, v)
|
|
default:
|
|
panic("cannot marshal unknown session token context")
|
|
}
|
|
}
|
|
|
|
return buf
|
|
}
|
|
|
|
func (t *TokenBody) StableSize() (size int) {
|
|
if t == nil {
|
|
return 0
|
|
}
|
|
|
|
size += proto.BytesSize(sessionTokenBodyIDField, t.id)
|
|
size += proto.NestedStructureSize(sessionTokenBodyOwnerField, t.ownerID)
|
|
size += proto.NestedStructureSize(sessionTokenBodyLifetimeField, t.lifetime)
|
|
size += proto.BytesSize(sessionTokenBodyKeyField, t.sessionKey)
|
|
|
|
if t.ctx != nil {
|
|
switch v := t.ctx.(type) {
|
|
case *ObjectSessionContext:
|
|
size += proto.NestedStructureSize(sessionTokenBodyObjectCtxField, v)
|
|
case *ContainerSessionContext:
|
|
size += proto.NestedStructureSize(sessionTokenBodyCnrCtxField, v)
|
|
default:
|
|
panic("cannot marshal unknown session token context")
|
|
}
|
|
}
|
|
|
|
return size
|
|
}
|
|
|
|
func (t *TokenBody) Unmarshal(data []byte) error {
|
|
m := new(session.SessionToken_Body)
|
|
if err := goproto.Unmarshal(data, m); err != nil {
|
|
return err
|
|
}
|
|
|
|
return t.FromGRPCMessage(m)
|
|
}
|
|
|
|
func (t *Token) StableMarshal(buf []byte) []byte {
|
|
if t == nil {
|
|
return []byte{}
|
|
}
|
|
|
|
if buf == nil {
|
|
buf = make([]byte, 0, t.StableSize())
|
|
}
|
|
|
|
buf = proto.NestedStructureMarshal(sessionTokenBodyField, buf, t.body)
|
|
buf = proto.NestedStructureMarshal(sessionTokenSignatureField, buf, t.sig)
|
|
|
|
return buf
|
|
}
|
|
|
|
func (t *Token) StableSize() (size int) {
|
|
if t == nil {
|
|
return 0
|
|
}
|
|
|
|
size += proto.NestedStructureSize(sessionTokenBodyField, t.body)
|
|
size += proto.NestedStructureSize(sessionTokenSignatureField, t.sig)
|
|
|
|
return size
|
|
}
|
|
|
|
func (t *Token) Unmarshal(data []byte) error {
|
|
m := new(session.SessionToken)
|
|
if err := goproto.Unmarshal(data, m); err != nil {
|
|
return err
|
|
}
|
|
|
|
return t.FromGRPCMessage(m)
|
|
}
|
|
|
|
func (r *RequestMetaHeader) StableMarshal(buf []byte) []byte {
|
|
if r == nil {
|
|
return []byte{}
|
|
}
|
|
|
|
if buf == nil {
|
|
buf = make([]byte, 0, r.StableSize())
|
|
}
|
|
|
|
buf = proto.NestedStructureMarshal(reqMetaHeaderVersionField, buf, r.version)
|
|
buf = proto.UInt64Marshal(reqMetaHeaderEpochField, buf, r.epoch)
|
|
buf = proto.UInt32Marshal(reqMetaHeaderTTLField, buf, r.ttl)
|
|
|
|
for i := range r.xHeaders {
|
|
buf = proto.NestedStructureMarshal(reqMetaHeaderXHeadersField, buf, &r.xHeaders[i])
|
|
}
|
|
|
|
buf = proto.NestedStructureMarshal(reqMetaHeaderSessionTokenField, buf, r.sessionToken)
|
|
buf = proto.NestedStructureMarshal(reqMetaHeaderBearerTokenField, buf, r.bearerToken)
|
|
buf = proto.NestedStructureMarshal(reqMetaHeaderOriginField, buf, r.origin)
|
|
buf = proto.UInt64Marshal(reqMetaHeaderNetMagicField, buf, r.netMagic)
|
|
|
|
return buf
|
|
}
|
|
|
|
func (r *RequestMetaHeader) StableSize() (size int) {
|
|
if r == nil {
|
|
return 0
|
|
}
|
|
|
|
if r.version != nil {
|
|
size += proto.NestedStructureSize(reqMetaHeaderVersionField, r.version)
|
|
}
|
|
|
|
size += proto.UInt64Size(reqMetaHeaderEpochField, r.epoch)
|
|
size += proto.UInt32Size(reqMetaHeaderTTLField, r.ttl)
|
|
|
|
for i := range r.xHeaders {
|
|
size += proto.NestedStructureSize(reqMetaHeaderXHeadersField, &r.xHeaders[i])
|
|
}
|
|
|
|
size += proto.NestedStructureSize(reqMetaHeaderSessionTokenField, r.sessionToken)
|
|
size += proto.NestedStructureSize(reqMetaHeaderBearerTokenField, r.bearerToken)
|
|
size += proto.NestedStructureSize(reqMetaHeaderOriginField, r.origin)
|
|
size += proto.UInt64Size(reqMetaHeaderNetMagicField, r.netMagic)
|
|
|
|
return size
|
|
}
|
|
|
|
func (r *RequestMetaHeader) Unmarshal(data []byte) error {
|
|
m := new(session.RequestMetaHeader)
|
|
if err := goproto.Unmarshal(data, m); err != nil {
|
|
return err
|
|
}
|
|
|
|
return r.FromGRPCMessage(m)
|
|
}
|
|
|
|
func (r *RequestVerificationHeader) StableMarshal(buf []byte) []byte {
|
|
if r == nil {
|
|
return []byte{}
|
|
}
|
|
|
|
if buf == nil {
|
|
buf = make([]byte, 0, r.StableSize())
|
|
}
|
|
|
|
buf = proto.NestedStructureMarshal(reqVerifHeaderBodySignatureField, buf, r.bodySig)
|
|
buf = proto.NestedStructureMarshal(reqVerifHeaderMetaSignatureField, buf, r.metaSig)
|
|
buf = proto.NestedStructureMarshal(reqVerifHeaderOriginSignatureField, buf, r.originSig)
|
|
buf = proto.NestedStructureMarshal(reqVerifHeaderOriginField, buf, r.origin)
|
|
|
|
return buf
|
|
}
|
|
|
|
func (r *RequestVerificationHeader) StableSize() (size int) {
|
|
if r == nil {
|
|
return 0
|
|
}
|
|
|
|
size += proto.NestedStructureSize(reqVerifHeaderBodySignatureField, r.bodySig)
|
|
size += proto.NestedStructureSize(reqVerifHeaderMetaSignatureField, r.metaSig)
|
|
size += proto.NestedStructureSize(reqVerifHeaderOriginSignatureField, r.originSig)
|
|
size += proto.NestedStructureSize(reqVerifHeaderOriginField, r.origin)
|
|
|
|
return size
|
|
}
|
|
|
|
func (r *RequestVerificationHeader) Unmarshal(data []byte) error {
|
|
m := new(session.RequestVerificationHeader)
|
|
if err := goproto.Unmarshal(data, m); err != nil {
|
|
return err
|
|
}
|
|
|
|
return r.FromGRPCMessage(m)
|
|
}
|
|
|
|
func (r *ResponseMetaHeader) StableMarshal(buf []byte) []byte {
|
|
if r == nil {
|
|
return []byte{}
|
|
}
|
|
|
|
if buf == nil {
|
|
buf = make([]byte, 0, r.StableSize())
|
|
}
|
|
|
|
buf = proto.NestedStructureMarshal(respMetaHeaderVersionField, buf, r.version)
|
|
buf = proto.UInt64Marshal(respMetaHeaderEpochField, buf, r.epoch)
|
|
buf = proto.UInt32Marshal(respMetaHeaderTTLField, buf, r.ttl)
|
|
|
|
for i := range r.xHeaders {
|
|
buf = proto.NestedStructureMarshal(respMetaHeaderXHeadersField, buf, &r.xHeaders[i])
|
|
}
|
|
|
|
buf = proto.NestedStructureMarshal(respMetaHeaderOriginField, buf, r.origin)
|
|
buf = proto.NestedStructureMarshal(respMetaHeaderStatusField, buf, r.status)
|
|
|
|
return buf
|
|
}
|
|
|
|
func (r *ResponseMetaHeader) StableSize() (size int) {
|
|
if r == nil {
|
|
return 0
|
|
}
|
|
|
|
if r.version != nil {
|
|
size += proto.NestedStructureSize(respMetaHeaderVersionField, r.version)
|
|
}
|
|
|
|
size += proto.UInt64Size(respMetaHeaderEpochField, r.epoch)
|
|
size += proto.UInt32Size(respMetaHeaderTTLField, r.ttl)
|
|
|
|
for i := range r.xHeaders {
|
|
size += proto.NestedStructureSize(respMetaHeaderXHeadersField, &r.xHeaders[i])
|
|
}
|
|
|
|
size += proto.NestedStructureSize(respMetaHeaderOriginField, r.origin)
|
|
size += proto.NestedStructureSize(respMetaHeaderStatusField, r.status)
|
|
|
|
return size
|
|
}
|
|
|
|
func (r *ResponseMetaHeader) Unmarshal(data []byte) error {
|
|
m := new(session.ResponseMetaHeader)
|
|
if err := goproto.Unmarshal(data, m); err != nil {
|
|
return err
|
|
}
|
|
|
|
return r.FromGRPCMessage(m)
|
|
}
|
|
|
|
func (r *ResponseVerificationHeader) StableMarshal(buf []byte) []byte {
|
|
if r == nil {
|
|
return []byte{}
|
|
}
|
|
|
|
if buf == nil {
|
|
buf = make([]byte, 0, r.StableSize())
|
|
}
|
|
|
|
buf = proto.NestedStructureMarshal(respVerifHeaderBodySignatureField, buf, r.bodySig)
|
|
buf = proto.NestedStructureMarshal(respVerifHeaderMetaSignatureField, buf, r.metaSig)
|
|
buf = proto.NestedStructureMarshal(respVerifHeaderOriginSignatureField, buf, r.originSig)
|
|
buf = proto.NestedStructureMarshal(respVerifHeaderOriginField, buf, r.origin)
|
|
|
|
return buf
|
|
}
|
|
|
|
func (r *ResponseVerificationHeader) StableSize() (size int) {
|
|
if r == nil {
|
|
return 0
|
|
}
|
|
|
|
size += proto.NestedStructureSize(respVerifHeaderBodySignatureField, r.bodySig)
|
|
size += proto.NestedStructureSize(respVerifHeaderMetaSignatureField, r.metaSig)
|
|
size += proto.NestedStructureSize(respVerifHeaderOriginSignatureField, r.originSig)
|
|
size += proto.NestedStructureSize(respVerifHeaderOriginField, r.origin)
|
|
|
|
return size
|
|
}
|
|
|
|
func (r *ResponseVerificationHeader) Unmarshal(data []byte) error {
|
|
m := new(session.ResponseVerificationHeader)
|
|
if err := goproto.Unmarshal(data, m); err != nil {
|
|
return err
|
|
}
|
|
|
|
return r.FromGRPCMessage(m)
|
|
}
|