From fd3bf4a56b9bc7132c85e280545d491a340d4489 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 25 Feb 2022 10:36:46 +0300 Subject: [PATCH] Fix linter remarks Signed-off-by: Leonard Lyubich --- container/convert.go | 4 +-- container/types.go | 12 ++++----- object/convert.go | 2 +- object/types.go | 6 ++--- refs/types.go | 1 + session/convert.go | 12 ++++----- session/json.go | 8 +++--- session/marshal.go | 12 ++++----- session/test/generate.go | 8 +++--- session/types.go | 56 ++++++++++++++++++++++++---------------- 10 files changed, 67 insertions(+), 54 deletions(-) diff --git a/container/convert.go b/container/convert.go index 977ad77b..89e0153e 100644 --- a/container/convert.go +++ b/container/convert.go @@ -432,7 +432,7 @@ func (r *GetResponseBody) FromGRPCMessage(m grpc.Message) error { r.token = nil } else { if r.token == nil { - r.token = new(session.SessionToken) + r.token = new(session.Token) } err = r.token.FromGRPCMessage(token) @@ -1026,7 +1026,7 @@ func (r *GetExtendedACLResponseBody) FromGRPCMessage(m grpc.Message) error { r.token = nil } else { if r.token == nil { - r.token = new(session.SessionToken) + r.token = new(session.Token) } err = r.token.FromGRPCMessage(token) diff --git a/container/types.go b/container/types.go index 63449ef4..ea7fd9cb 100644 --- a/container/types.go +++ b/container/types.go @@ -59,7 +59,7 @@ type GetRequest struct { type GetResponseBody struct { cnr *Container - token *session.SessionToken + token *session.Token sig *refs.Signature } @@ -145,7 +145,7 @@ type GetExtendedACLResponseBody struct { sig *refs.Signature - token *session.SessionToken + token *session.Token } type GetExtendedACLResponse struct { @@ -406,7 +406,7 @@ func (r *GetResponseBody) SetContainer(v *Container) { // GetSessionToken returns token of the session within which requested // container was created. -func (r *GetResponseBody) GetSessionToken() *session.SessionToken { +func (r *GetResponseBody) GetSessionToken() *session.Token { if r != nil { return r.token } @@ -416,7 +416,7 @@ func (r *GetResponseBody) GetSessionToken() *session.SessionToken { // SetSessionToken sets token of the session within which requested // container was created. -func (r *GetResponseBody) SetSessionToken(v *session.SessionToken) { +func (r *GetResponseBody) SetSessionToken(v *session.Token) { if r != nil { r.token = v } @@ -678,7 +678,7 @@ func (r *GetExtendedACLResponseBody) SetSignature(v *refs.Signature) { // GetSessionToken returns token of the session within which requested // eACL table was set. -func (r *GetExtendedACLResponseBody) GetSessionToken() *session.SessionToken { +func (r *GetExtendedACLResponseBody) GetSessionToken() *session.Token { if r != nil { return r.token } @@ -688,7 +688,7 @@ func (r *GetExtendedACLResponseBody) GetSessionToken() *session.SessionToken { // SetSessionToken sets token of the session within which requested // eACL table was set. -func (r *GetExtendedACLResponseBody) SetSessionToken(v *session.SessionToken) { +func (r *GetExtendedACLResponseBody) SetSessionToken(v *session.Token) { if r != nil { r.token = v } diff --git a/object/convert.go b/object/convert.go index d7c0a28e..80213df6 100644 --- a/object/convert.go +++ b/object/convert.go @@ -373,7 +373,7 @@ func (h *Header) FromGRPCMessage(m grpc.Message) error { h.sessionToken = nil } else { if h.sessionToken == nil { - h.sessionToken = new(session.SessionToken) + h.sessionToken = new(session.Token) } err = h.sessionToken.FromGRPCMessage(sessionToken) diff --git a/object/types.go b/object/types.go index 0c101b50..ed3cdffe 100644 --- a/object/types.go +++ b/object/types.go @@ -54,7 +54,7 @@ type Header struct { typ Type - sessionToken *session.SessionToken + sessionToken *session.Token attr []*Attribute @@ -640,7 +640,7 @@ func (h *Header) SetHomomorphicHash(v *refs.Checksum) { } } -func (h *Header) GetSessionToken() *session.SessionToken { +func (h *Header) GetSessionToken() *session.Token { if h != nil { return h.sessionToken } @@ -648,7 +648,7 @@ func (h *Header) GetSessionToken() *session.SessionToken { return nil } -func (h *Header) SetSessionToken(v *session.SessionToken) { +func (h *Header) SetSessionToken(v *session.Token) { if h != nil { h.sessionToken = v } diff --git a/refs/types.go b/refs/types.go index 93a814ac..dbe307a8 100644 --- a/refs/types.go +++ b/refs/types.go @@ -33,6 +33,7 @@ type ChecksumType uint32 type SignatureScheme uint32 +//nolint:revive const ( UnspecifiedScheme SignatureScheme = iota ECDSA_SHA512 diff --git a/session/convert.go b/session/convert.go index 5562fffb..200e2274 100644 --- a/session/convert.go +++ b/session/convert.go @@ -242,7 +242,7 @@ func XHeadersFromGRPC(xs []*session.XHeader) (res []*XHeader, err error) { return } -func (t *SessionToken) ToGRPCMessage() grpc.Message { +func (t *Token) ToGRPCMessage() grpc.Message { var m *session.SessionToken if t != nil { @@ -255,7 +255,7 @@ func (t *SessionToken) ToGRPCMessage() grpc.Message { return m } -func (t *SessionToken) FromGRPCMessage(m grpc.Message) error { +func (t *Token) FromGRPCMessage(m grpc.Message) error { v, ok := m.(*session.SessionToken) if !ok { return message.NewUnexpectedMessageType(m, v) @@ -268,7 +268,7 @@ func (t *SessionToken) FromGRPCMessage(m grpc.Message) error { t.body = nil } else { if t.body == nil { - t.body = new(SessionTokenBody) + t.body = new(TokenBody) } err = t.body.FromGRPCMessage(body) @@ -422,7 +422,7 @@ func (r *RequestMetaHeader) FromGRPCMessage(m grpc.Message) error { r.sessionToken = nil } else { if r.sessionToken == nil { - r.sessionToken = new(SessionToken) + r.sessionToken = new(Token) } err = r.sessionToken.FromGRPCMessage(sessionToken) @@ -713,7 +713,7 @@ func (c *ObjectSessionContext) FromGRPCMessage(m grpc.Message) error { return nil } -func (t *SessionTokenBody) ToGRPCMessage() grpc.Message { +func (t *TokenBody) ToGRPCMessage() grpc.Message { var m *session.SessionToken_Body if t != nil { @@ -739,7 +739,7 @@ func (t *SessionTokenBody) ToGRPCMessage() grpc.Message { return m } -func (t *SessionTokenBody) FromGRPCMessage(m grpc.Message) error { +func (t *TokenBody) FromGRPCMessage(m grpc.Message) error { v, ok := m.(*session.SessionToken_Body) if !ok { return message.NewUnexpectedMessageType(m, v) diff --git a/session/json.go b/session/json.go index d8056eed..b4235677 100644 --- a/session/json.go +++ b/session/json.go @@ -22,11 +22,11 @@ func (l *TokenLifetime) UnmarshalJSON(data []byte) error { return message.UnmarshalJSON(l, data, new(session.SessionToken_Body_TokenLifetime)) } -func (t *SessionTokenBody) MarshalJSON() ([]byte, error) { +func (t *TokenBody) MarshalJSON() ([]byte, error) { return message.MarshalJSON(t) } -func (t *SessionTokenBody) UnmarshalJSON(data []byte) error { +func (t *TokenBody) UnmarshalJSON(data []byte) error { msg := new(session.SessionToken_Body) if err := protojson.Unmarshal(data, msg); err != nil { @@ -36,11 +36,11 @@ func (t *SessionTokenBody) UnmarshalJSON(data []byte) error { return t.FromGRPCMessage(msg) } -func (t *SessionToken) MarshalJSON() ([]byte, error) { +func (t *Token) MarshalJSON() ([]byte, error) { return message.MarshalJSON(t) } -func (t *SessionToken) UnmarshalJSON(data []byte) error { +func (t *Token) UnmarshalJSON(data []byte) error { msg := new(session.SessionToken) if err := protojson.Unmarshal(data, msg); err != nil { diff --git a/session/marshal.go b/session/marshal.go index f28615c7..dbaf367d 100644 --- a/session/marshal.go +++ b/session/marshal.go @@ -363,7 +363,7 @@ func (x *ContainerSessionContext) Unmarshal(data []byte) error { return message.Unmarshal(x, data, new(session.ContainerSessionContext)) } -func (t *SessionTokenBody) StableMarshal(buf []byte) ([]byte, error) { +func (t *TokenBody) StableMarshal(buf []byte) ([]byte, error) { if t == nil { return []byte{}, nil } @@ -425,7 +425,7 @@ func (t *SessionTokenBody) StableMarshal(buf []byte) ([]byte, error) { return buf, nil } -func (t *SessionTokenBody) StableSize() (size int) { +func (t *TokenBody) StableSize() (size int) { if t == nil { return 0 } @@ -449,7 +449,7 @@ func (t *SessionTokenBody) StableSize() (size int) { return size } -func (t *SessionTokenBody) Unmarshal(data []byte) error { +func (t *TokenBody) Unmarshal(data []byte) error { m := new(session.SessionToken_Body) if err := goproto.Unmarshal(data, m); err != nil { return err @@ -458,7 +458,7 @@ func (t *SessionTokenBody) Unmarshal(data []byte) error { return t.FromGRPCMessage(m) } -func (t *SessionToken) StableMarshal(buf []byte) ([]byte, error) { +func (t *Token) StableMarshal(buf []byte) ([]byte, error) { if t == nil { return []byte{}, nil } @@ -487,7 +487,7 @@ func (t *SessionToken) StableMarshal(buf []byte) ([]byte, error) { return buf, nil } -func (t *SessionToken) StableSize() (size int) { +func (t *Token) StableSize() (size int) { if t == nil { return 0 } @@ -498,7 +498,7 @@ func (t *SessionToken) StableSize() (size int) { return size } -func (t *SessionToken) Unmarshal(data []byte) error { +func (t *Token) Unmarshal(data []byte) error { m := new(session.SessionToken) if err := goproto.Unmarshal(data, m); err != nil { return err diff --git a/session/test/generate.go b/session/test/generate.go index d8095925..537240ae 100644 --- a/session/test/generate.go +++ b/session/test/generate.go @@ -145,8 +145,8 @@ func generateRequestMetaHeader(empty, withOrigin bool) *session.RequestMetaHeade return m } -func GenerateSessionToken(empty bool) *session.SessionToken { - m := new(session.SessionToken) +func GenerateSessionToken(empty bool) *session.Token { + m := new(session.Token) if !empty { m.SetBody(GenerateSessionTokenBody(false)) @@ -157,8 +157,8 @@ func GenerateSessionToken(empty bool) *session.SessionToken { return m } -func GenerateSessionTokenBody(empty bool) *session.SessionTokenBody { - m := new(session.SessionTokenBody) +func GenerateSessionTokenBody(empty bool) *session.TokenBody { + m := new(session.TokenBody) if !empty { m.SetID([]byte{1}) diff --git a/session/types.go b/session/types.go index 26fa26ed..e41b5a9b 100644 --- a/session/types.go +++ b/session/types.go @@ -46,11 +46,15 @@ type ObjectSessionContext struct { addr *refs.Address } -type SessionTokenContext interface { +type TokenContext interface { sessionTokenContext() } -type SessionTokenBody struct { +// Deprecated: use TokenContext instead. +//nolint:revive +type SessionTokenContext = TokenContext + +type TokenBody struct { id []byte ownerID *refs.OwnerID @@ -59,15 +63,23 @@ type SessionTokenBody struct { sessionKey []byte - ctx SessionTokenContext + ctx TokenContext } -type SessionToken struct { - body *SessionTokenBody +// Deprecated: use TokenBody instead. +//nolint:revive +type SessionTokenBody = TokenBody + +type Token struct { + body *TokenBody sig *refs.Signature } +// Deprecated: use Token instead. +//nolint:revive +type SessionToken = Token + type RequestVerificationHeader struct { bodySig, metaSig, originSig *refs.Signature @@ -83,7 +95,7 @@ type RequestMetaHeader struct { xHeaders []*XHeader - sessionToken *SessionToken + sessionToken *Token bearerToken *acl.BearerToken @@ -403,7 +415,7 @@ func (r *RequestMetaHeader) SetXHeaders(v []*XHeader) { } } -func (r *RequestMetaHeader) GetSessionToken() *SessionToken { +func (r *RequestMetaHeader) GetSessionToken() *Token { if r != nil { return r.sessionToken } @@ -411,7 +423,7 @@ func (r *RequestMetaHeader) GetSessionToken() *SessionToken { return nil } -func (r *RequestMetaHeader) SetSessionToken(v *SessionToken) { +func (r *RequestMetaHeader) SetSessionToken(v *Token) { if r != nil { r.sessionToken = v } @@ -692,7 +704,7 @@ func (c *ObjectSessionContext) SetAddress(v *refs.Address) { } } -func (t *SessionTokenBody) GetID() []byte { +func (t *TokenBody) GetID() []byte { if t != nil { return t.id } @@ -700,13 +712,13 @@ func (t *SessionTokenBody) GetID() []byte { return nil } -func (t *SessionTokenBody) SetID(v []byte) { +func (t *TokenBody) SetID(v []byte) { if t != nil { t.id = v } } -func (t *SessionTokenBody) GetOwnerID() *refs.OwnerID { +func (t *TokenBody) GetOwnerID() *refs.OwnerID { if t != nil { return t.ownerID } @@ -714,13 +726,13 @@ func (t *SessionTokenBody) GetOwnerID() *refs.OwnerID { return nil } -func (t *SessionTokenBody) SetOwnerID(v *refs.OwnerID) { +func (t *TokenBody) SetOwnerID(v *refs.OwnerID) { if t != nil { t.ownerID = v } } -func (t *SessionTokenBody) GetLifetime() *TokenLifetime { +func (t *TokenBody) GetLifetime() *TokenLifetime { if t != nil { return t.lifetime } @@ -728,13 +740,13 @@ func (t *SessionTokenBody) GetLifetime() *TokenLifetime { return nil } -func (t *SessionTokenBody) SetLifetime(v *TokenLifetime) { +func (t *TokenBody) SetLifetime(v *TokenLifetime) { if t != nil { t.lifetime = v } } -func (t *SessionTokenBody) GetSessionKey() []byte { +func (t *TokenBody) GetSessionKey() []byte { if t != nil { return t.sessionKey } @@ -742,13 +754,13 @@ func (t *SessionTokenBody) GetSessionKey() []byte { return nil } -func (t *SessionTokenBody) SetSessionKey(v []byte) { +func (t *TokenBody) SetSessionKey(v []byte) { if t != nil { t.sessionKey = v } } -func (t *SessionTokenBody) GetContext() SessionTokenContext { +func (t *TokenBody) GetContext() TokenContext { if t != nil { return t.ctx } @@ -756,13 +768,13 @@ func (t *SessionTokenBody) GetContext() SessionTokenContext { return nil } -func (t *SessionTokenBody) SetContext(v SessionTokenContext) { +func (t *TokenBody) SetContext(v TokenContext) { if t != nil { t.ctx = v } } -func (t *SessionToken) GetBody() *SessionTokenBody { +func (t *Token) GetBody() *TokenBody { if t != nil { return t.body } @@ -770,13 +782,13 @@ func (t *SessionToken) GetBody() *SessionTokenBody { return nil } -func (t *SessionToken) SetBody(v *SessionTokenBody) { +func (t *Token) SetBody(v *TokenBody) { if t != nil { t.body = v } } -func (t *SessionToken) GetSignature() *refs.Signature { +func (t *Token) GetSignature() *refs.Signature { if t != nil { return t.sig } @@ -784,7 +796,7 @@ func (t *SessionToken) GetSignature() *refs.Signature { return nil } -func (t *SessionToken) SetSignature(v *refs.Signature) { +func (t *Token) SetSignature(v *refs.Signature) { if t != nil { t.sig = v }