diff --git a/v2/acl/convert.go b/v2/acl/convert.go index e05ee07..f41a28d 100644 --- a/v2/acl/convert.go +++ b/v2/acl/convert.go @@ -31,108 +31,108 @@ func TargetFromGRPCField(t acl.Target) Target { } } -func OperationToGRPCField(t Operation) acl.EACLRecord_Operation { +func OperationToGRPCField(t Operation) acl.Operation { switch t { case OperationPut: - return acl.EACLRecord_PUT + return acl.Operation_PUT case OperationDelete: - return acl.EACLRecord_DELETE + return acl.Operation_DELETE case OperationGet: - return acl.EACLRecord_GET + return acl.Operation_GET case OperationHead: - return acl.EACLRecord_HEAD + return acl.Operation_HEAD case OperationSearch: - return acl.EACLRecord_SEARCH + return acl.Operation_SEARCH case OperationRange: - return acl.EACLRecord_GETRANGE + return acl.Operation_GETRANGE case OperationRangeHash: - return acl.EACLRecord_GETRANGEHASH + return acl.Operation_GETRANGEHASH default: - return acl.EACLRecord_OPERATION_UNSPECIFIED + return acl.Operation_OPERATION_UNSPECIFIED } } -func OperationFromGRPCField(t acl.EACLRecord_Operation) Operation { +func OperationFromGRPCField(t acl.Operation) Operation { switch t { - case acl.EACLRecord_PUT: + case acl.Operation_PUT: return OperationPut - case acl.EACLRecord_DELETE: + case acl.Operation_DELETE: return OperationDelete - case acl.EACLRecord_GET: + case acl.Operation_GET: return OperationGet - case acl.EACLRecord_HEAD: + case acl.Operation_HEAD: return OperationHead - case acl.EACLRecord_SEARCH: + case acl.Operation_SEARCH: return OperationSearch - case acl.EACLRecord_GETRANGE: + case acl.Operation_GETRANGE: return OperationRange - case acl.EACLRecord_GETRANGEHASH: + case acl.Operation_GETRANGEHASH: return OperationRangeHash default: return OperationUnknown } } -func ActionToGRPCField(t Action) acl.EACLRecord_Action { +func ActionToGRPCField(t Action) acl.Action { switch t { case ActionDeny: - return acl.EACLRecord_DENY + return acl.Action_DENY case ActionAllow: - return acl.EACLRecord_ALLOW + return acl.Action_ALLOW default: - return acl.EACLRecord_ACTION_UNSPECIFIED + return acl.Action_ACTION_UNSPECIFIED } } -func ActionFromGRPCField(t acl.EACLRecord_Action) Action { +func ActionFromGRPCField(t acl.Action) Action { switch t { - case acl.EACLRecord_DENY: + case acl.Action_DENY: return ActionDeny - case acl.EACLRecord_ALLOW: + case acl.Action_ALLOW: return ActionAllow default: return ActionUnknown } } -func HeaderTypeToGRPCField(t HeaderType) acl.EACLRecord_FilterInfo_Header { +func HeaderTypeToGRPCField(t HeaderType) acl.HeaderType { switch t { case HeaderTypeRequest: - return acl.EACLRecord_FilterInfo_REQUEST + return acl.HeaderType_REQUEST case HeaderTypeObject: - return acl.EACLRecord_FilterInfo_OBJECT + return acl.HeaderType_OBJECT default: - return acl.EACLRecord_FilterInfo_HEADER_UNSPECIFIED + return acl.HeaderType_HEADER_UNSPECIFIED } } -func HeaderTypeFromGRPCField(t acl.EACLRecord_FilterInfo_Header) HeaderType { +func HeaderTypeFromGRPCField(t acl.HeaderType) HeaderType { switch t { - case acl.EACLRecord_FilterInfo_REQUEST: + case acl.HeaderType_REQUEST: return HeaderTypeRequest - case acl.EACLRecord_FilterInfo_OBJECT: + case acl.HeaderType_OBJECT: return HeaderTypeObject default: return HeaderTypeUnknown } } -func MatchTypeToGRPCField(t MatchType) acl.EACLRecord_FilterInfo_MatchType { +func MatchTypeToGRPCField(t MatchType) acl.MatchType { switch t { case MatchTypeStringEqual: - return acl.EACLRecord_FilterInfo_STRING_EQUAL + return acl.MatchType_STRING_EQUAL case MatchTypeStringNotEqual: - return acl.EACLRecord_FilterInfo_STRING_NOT_EQUAL + return acl.MatchType_STRING_NOT_EQUAL default: - return acl.EACLRecord_FilterInfo_MATCH_TYPE_UNSPECIFIED + return acl.MatchType_MATCH_TYPE_UNSPECIFIED } } -func MatchTypeFromGRPCField(t acl.EACLRecord_FilterInfo_MatchType) MatchType { +func MatchTypeFromGRPCField(t acl.MatchType) MatchType { switch t { - case acl.EACLRecord_FilterInfo_STRING_EQUAL: + case acl.MatchType_STRING_EQUAL: return MatchTypeStringEqual - case acl.EACLRecord_FilterInfo_STRING_NOT_EQUAL: + case acl.MatchType_STRING_NOT_EQUAL: return MatchTypeStringNotEqual default: return MatchTypeUnknown diff --git a/v2/acl/grpc/types.go b/v2/acl/grpc/types.go index 3091259..da83e24 100644 --- a/v2/acl/grpc/types.go +++ b/v2/acl/grpc/types.go @@ -19,14 +19,14 @@ func (m *EACLTable) SetRecords(v []*EACLRecord) { } // SetOperation sets operation of the eACL record. -func (m *EACLRecord) SetOperation(v EACLRecord_Operation) { +func (m *EACLRecord) SetOperation(v Operation) { if m != nil { m.Operation = v } } // SetAction sets action of the eACL record. -func (m *EACLRecord) SetAction(v EACLRecord_Action) { +func (m *EACLRecord) SetAction(v Action) { if m != nil { m.Action = v } @@ -47,14 +47,14 @@ func (m *EACLRecord) SetTargets(v []*EACLRecord_TargetInfo) { } // SetHeader sets header type of the eACL filter. -func (m *EACLRecord_FilterInfo) SetHeader(v EACLRecord_FilterInfo_Header) { +func (m *EACLRecord_FilterInfo) SetHeader(v HeaderType) { if m != nil { m.Header = v } } // SetMatchType sets match type of the eACL filter. -func (m *EACLRecord_FilterInfo) SetMatchType(v EACLRecord_FilterInfo_MatchType) { +func (m *EACLRecord_FilterInfo) SetMatchType(v MatchType) { if m != nil { m.MatchType = v } diff --git a/v2/container/grpc/marshal.go b/v2/container/grpc/marshal.go deleted file mode 100644 index aa04626..0000000 --- a/v2/container/grpc/marshal.go +++ /dev/null @@ -1,238 +0,0 @@ -package container - -import ( - "encoding/binary" - "math/bits" - - "github.com/pkg/errors" -) - -// StableMarshal marshals auto-generated container structure into -// protobuf-compatible stable byte sequence. -func (m *Container) StableMarshal(buf []byte) ([]byte, error) { - if m == nil { - return []byte{}, nil - } - - if buf == nil { - buf = make([]byte, m.StableSize()) - } - - var ( - i, n, offset int - ) - - // Write owner id field. - - if m.OwnerId != nil { - buf[i] = 0x0A // id:0x1 << 3 | wiretype:0x2 - n = m.OwnerId.StableSize() - offset = binary.PutUvarint(buf[i+1:], uint64(n)) - - _, err := m.OwnerId.StableMarshal(buf[i+1+offset:]) - if err != nil { - return nil, errors.Wrapf(err, "can't marshal owner id") - } - - i += 1 + offset + n - } - - // Write salt field. - - buf[i] = 0x12 // id:0x2 << 3 | wiretype:0x2 - offset = binary.PutUvarint(buf[i+1:], uint64(len(m.Nonce))) - n = copy(buf[i+1+offset:], m.Nonce) - i += 1 + offset + n - - // Write basic acl field. - - buf[i] = 0x18 // id:0x3 << 3 | wiretype:0x0 - offset = binary.PutUvarint(buf[i+1:], uint64(m.BasicAcl)) - i += 1 + offset - - // Write attributes field. - - for j := range m.Attributes { - buf[i] = 0x22 // id:0x4 << 3 | wiretype:0x2 - n = m.Attributes[j].StableSize() - offset = binary.PutUvarint(buf[i+1:], uint64(n)) - - _, err := m.Attributes[j].StableMarshal(buf[i+1+offset:]) - if err != nil { - return nil, errors.Wrapf(err, "can't marshal attribute %v", - m.Attributes[i].Key) - } - - i += 1 + offset + n - } - - // Write placement rule field. - - if m.PlacementPolicy != nil { - buf[i] = 0x2A // id:0x5 << 3 | wiretype:0x2 - n = m.PlacementPolicy.StableSize() - offset = binary.PutUvarint(buf[i+1:], uint64(n)) - - _, err := m.PlacementPolicy.StableMarshal(buf[i+1+offset:]) - if err != nil { - return nil, errors.Wrapf(err, "can't marshal attribute %v", - m.Attributes[i].Key) - } - } - - return buf, nil -} - -func (m *Container) StableSize() int { - if m == nil { - return 0 - } - - var ( - ln, size int - ) - - if m.OwnerId != nil { - ln = m.OwnerId.StableSize() - } - size += 1 + uvarIntSize(uint64(ln)) + ln // wiretype + bytes length + bytes - - ln = len(m.Nonce) // size of salt field - size += 1 + uvarIntSize(uint64(ln)) + ln // wiretype + bytes length + bytes - - // size of basic acl field - size += 1 + uvarIntSize(uint64(m.BasicAcl)) // wiretype + varint - - // size of attributes - for i := range m.Attributes { - ln = m.Attributes[i].StableSize() - size += 1 + uvarIntSize(uint64(ln)) + ln // wiretype + size of struct + struct - } - - // size of placement rule - if m.PlacementPolicy != nil { - ln = m.PlacementPolicy.StableSize() - size += 1 + uvarIntSize(uint64(ln)) + ln // wiretype + size of struct + struct - } - - return size -} - -func (m *Container_Attribute) StableMarshal(buf []byte) ([]byte, error) { - if m == nil { - return []byte{}, nil - } - - if buf == nil { - buf = make([]byte, m.StableSize()) - } - - var ( - i, n, offset int - ) - - // Write key field. - - buf[i] = 0x0A // id:0x1 << 3 | wiretype:0x2 - offset = binary.PutUvarint(buf[i+1:], uint64(len(m.Key))) - n = copy(buf[i+1+offset:], m.Key) - i += 1 + offset + n - - // Write value field. - - buf[i] = 0x12 // id:0x2 << 3 | wiretype:0x2 - offset = binary.PutUvarint(buf[i+1:], uint64(len(m.Value))) - copy(buf[i+1+offset:], m.Value) - - return buf, nil -} - -func (m *Container_Attribute) StableSize() int { - if m == nil { - return 0 - } - - var ( - ln, size int - ) - - ln = len(m.Key) // size of key field - size += 1 + uvarIntSize(uint64(ln)) + ln // wiretype + size of string + string - - ln = len(m.Value) // size of value field - size += 1 + uvarIntSize(uint64(ln)) + ln // wiretype + size of string + string - - return size -} - -func (m *PutRequest_Body) StableMarshal(buf []byte) ([]byte, error) { - if m == nil { - return []byte{}, nil - } - - if buf == nil { - buf = make([]byte, m.StableSize()) - } - - var ( - i, n, offset int - ) - - // Write container field. - - if m.Container != nil { - buf[i] = 0x0A // id:0x1 << 3 | wiretype:0x2 - n = m.Container.StableSize() - offset = binary.PutUvarint(buf[i+1:], uint64(n)) - - _, err := m.Container.StableMarshal(buf[i+1+offset:]) - if err != nil { - return nil, errors.Wrapf(err, "can't marshal container") - } - - i += 1 + offset + n - } - - // Write public key field. - - buf[i] = 0x12 // id:0x2 << 3 | wiretype:0x2 - offset = binary.PutUvarint(buf[i+1:], uint64(len(m.PublicKey))) - n = copy(buf[i+1+offset:], m.PublicKey) - i += 1 + offset + n - - // Write signature field. - - buf[i] = 0x1A // id:0x3 << 3 | wiretype:0x2 - offset = binary.PutUvarint(buf[i+1:], uint64(len(m.Signature))) - copy(buf[i+1+offset:], m.Signature) - - return buf, nil -} - -func (m *PutRequest_Body) StableSize() int { - if m == nil { - return 0 - } - - var ( - ln, size int - ) - - if m.Container != nil { - ln = m.Container.StableSize() - size += 1 + uvarIntSize(uint64(ln)) + ln // wiretype + size of string + string - } - - ln = len(m.PublicKey) - size += 1 + uvarIntSize(uint64(ln)) + ln // wiretype + size of string + string - - ln = len(m.Signature) - size += 1 + uvarIntSize(uint64(ln)) + ln // wiretype + size of string + string - - return size -} - -// uvarIntSize returns length of varint byte sequence for uint64 value 'x'. -func uvarIntSize(x uint64) int { - return (bits.Len64(x|1) + 6) / 7 -} diff --git a/v2/container/grpc/marshal_test.go b/v2/container/grpc/marshal_test.go deleted file mode 100644 index ef8bfdd..0000000 --- a/v2/container/grpc/marshal_test.go +++ /dev/null @@ -1,77 +0,0 @@ -package container - -import ( - "testing" - - netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc" - refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc" - "github.com/stretchr/testify/require" -) - -var ( - cnr = &Container{ - OwnerId: &refs.OwnerID{Value: []byte("Owner")}, - Nonce: []byte("Salt"), - BasicAcl: 505, - Attributes: []*Container_Attribute{ - { - Key: "Hello", - Value: "World", - }, - { - Key: "Privet", - Value: "Mir", - }, - }, - PlacementPolicy: &netmap.PlacementPolicy{ - ReplFactor: 4, - FilterGroups: []*netmap.PlacementPolicy_FilterGroup{ - { - Selectors: []*netmap.PlacementPolicy_FilterGroup_Selector{ - { - Count: 1, - Key: "Node", - }, - }, - Filters: []*netmap.PlacementPolicy_FilterGroup_Filter{ - { - Key: "City", - }, - { - Key: "Datacenter", - }, - }, - Exclude: []uint32{4, 5, 6}, - }, - }, - }, - } -) - -func TestContainer_StableMarshal(t *testing.T) { - newCnr := new(Container) - - wire, err := cnr.StableMarshal(nil) - require.NoError(t, err) - - err = newCnr.Unmarshal(wire) - require.NoError(t, err) - - require.Equal(t, cnr, newCnr) -} - -func TestPutRequest_Body_StableMarshal(t *testing.T) { - expectedBody := new(PutRequest_Body) - expectedBody.Container = cnr - expectedBody.PublicKey = []byte{1, 2, 3, 4} - expectedBody.Signature = []byte{5, 6, 7, 8} - - wire, err := expectedBody.StableMarshal(nil) - require.NoError(t, err) - - gotBody := new(PutRequest_Body) - err = gotBody.Unmarshal(wire) - require.NoError(t, err) - - require.Equal(t, expectedBody, gotBody) -} diff --git a/v2/container/grpc/signature.go b/v2/container/grpc/signature.go deleted file mode 100644 index 0bdb334..0000000 --- a/v2/container/grpc/signature.go +++ /dev/null @@ -1,17 +0,0 @@ -package container - -func (m *Container) ReadSignedData(buf []byte) ([]byte, error) { - return m.StableMarshal(buf) -} - -func (m *Container) SignedDataSize() int { - return m.StableSize() -} - -func (m *PutRequest_Body) ReadSignedData(buf []byte) ([]byte, error) { - return m.StableMarshal(buf) -} - -func (m *PutRequest_Body) SignedDataSize() int { - return m.StableSize() -} diff --git a/v2/object/grpc/service.go b/v2/object/grpc/service.go index 0372b3d..1b95500 100644 --- a/v2/object/grpc/service.go +++ b/v2/object/grpc/service.go @@ -296,35 +296,35 @@ func (m *HeadRequest) SetVerifyHeader(v *service.RequestVerificationHeader) { // SetVersion sets version of the object format. func (m *HeadResponse_Body_ShortHeader) SetVersion(v *service.Version) { if m != nil { - m.Version = v + m.ShortHeader.Version = v } } // SetCreationEpoch sets creation epoch number of the object. func (m *HeadResponse_Body_ShortHeader) SetCreationEpoch(v uint64) { if m != nil { - m.CreationEpoch = v + m.ShortHeader.CreationEpoch = v } } // SetOwnerId sets identifier of the object owner. func (m *HeadResponse_Body_ShortHeader) SetOwnerId(v *refs.OwnerID) { if m != nil { - m.OwnerId = v + m.ShortHeader.OwnerId = v } } // SetObjectType sets type of the object. func (m *HeadResponse_Body_ShortHeader) SetObjectType(v ObjectType) { if m != nil { - m.ObjectType = v + m.ShortHeader.ObjectType = v } } // SetPayloadLength sets length of the object payload. func (m *HeadResponse_Body_ShortHeader) SetPayloadLength(v uint64) { if m != nil { - m.PayloadLength = v + m.ShortHeader.PayloadLength = v } } @@ -340,9 +340,7 @@ func (m *HeadResponse_Body) SetHeader(v *Header) { // SetShortHeader sets short header of the object. func (m *HeadResponse_Body) SetShortHeader(v *HeadResponse_Body_ShortHeader) { if m != nil { - m.Head = &HeadResponse_Body_ShortHeader_{ - ShortHeader: v, - } + m.Head = v } } @@ -368,7 +366,7 @@ func (m *HeadResponse) SetVerifyHeader(v *service.ResponseVerificationHeader) { } // SetMatchType sets match type of the filter. -func (m *SearchRequest_Body_Filter) SetMatchType(v SearchRequest_Body_Filter_MatchType) { +func (m *SearchRequest_Body_Filter) SetMatchType(v MatchType) { if m != nil { m.MatchType = v } diff --git a/v2/service/grpc/meta.go b/v2/service/grpc/meta.go index c5e9c78..730b437 100644 --- a/v2/service/grpc/meta.go +++ b/v2/service/grpc/meta.go @@ -68,13 +68,6 @@ func (m *SessionToken_Body) SetOwnerId(v *refs.OwnerID) { } } -// SetVerb sets verb of the session token. -func (m *SessionToken_Body) SetVerb(v SessionToken_Body_Verb) { - if m != nil { - m.Verb = v - } -} - // SetLifetime sets lifetime of the session token. func (m *SessionToken_Body) SetLifetime(v *TokenLifetime) { if m != nil { @@ -90,14 +83,28 @@ func (m *SessionToken_Body) SetSessionKey(v []byte) { } // SetObjectAddressContext sets object context of the session token. -func (m *SessionToken_Body) SetObjectAddressContext(v *refs.Address) { +func (m *SessionToken_Body) SetObjectServiceContext(v *ObjectServiceContext) { if m != nil { - m.Context = &SessionToken_Body_ObjectAddress{ - ObjectAddress: v, + m.Context = &SessionToken_Body_ObjectService{ + ObjectService: v, } } } +// SetObjectAddressContext sets object context of the session token. +func (m *ObjectServiceContext) SetAddress(v *refs.Address) { + if m != nil { + m.Address = v + } +} + +// SetObjectAddressContext sets object context of the session token. +func (m *ObjectServiceContext) SetVerb(v ObjectServiceContext_Verb) { + if m != nil { + m.Verb = v + } +} + // SetBody sets session token body. func (m *SessionToken) SetBody(v *SessionToken_Body) { if m != nil {