diff --git a/prepare.sh b/prepare.sh index 5962123..c0e4a37 100755 --- a/prepare.sh +++ b/prepare.sh @@ -16,13 +16,16 @@ cd $API_PATH ARGS=$(find ./ -name '*.proto' -not -path './vendor/*') for file in $ARGS; do dir=$(dirname $file) - cp -r $dir $API_GO_PATH/$prefix + mkdir -p $API_GO_PATH/$prefix/$dir/grpc + cp -r $dir/* $API_GO_PATH/$prefix/$dir/grpc done # MODIFY FILES cd $API_GO_PATH/$prefix -for file in $ARGS; do - sed -i "s/import\ \"\(.*\)\";/import\ \"$prefix\/\1\";/" $file +ARGS2=$(find ./ -name '*.proto') +for file in $ARGS2; do + echo $file + sed -i "s/import\ \"\(.*\)\/\(.*\)\.proto\";/import\ \"$prefix\/\1\/grpc\/\2\.proto\";/" $file done cd $API_GO_PATH @@ -30,7 +33,7 @@ cd $API_GO_PATH make protoc # REMOVE PROTO DEFINITIONS -ARGS=$(find ./ -name '*.proto' -not -path './vendor/*') +ARGS=$(find ./$prefix -name '*.proto' -not -path './vendor/*') for file in $ARGS; do rm $file done diff --git a/v2/accounting.go b/v2/accounting/accounting.go similarity index 57% rename from v2/accounting.go rename to v2/accounting/accounting.go index a14e5a1..a49f79b 100644 --- a/v2/accounting.go +++ b/v2/accounting/accounting.go @@ -1,18 +1,23 @@ -package v2 +package accounting + +import ( + "github.com/nspcc-dev/neofs-api-go/v2/refs" + "github.com/nspcc-dev/neofs-api-go/v2/service" +) type BalanceRequestBody struct { - ownerID *OwnerID + ownerID *refs.OwnerID } type BalanceRequest struct { body *BalanceRequestBody - metaHeader *RequestMetaHeader + metaHeader *service.RequestMetaHeader - verifyHeader *RequestVerificationHeader + verifyHeader *service.RequestVerificationHeader } -func (b *BalanceRequestBody) GetOwnerID() *OwnerID { +func (b *BalanceRequestBody) GetOwnerID() *refs.OwnerID { if b != nil { return b.ownerID } @@ -20,7 +25,7 @@ func (b *BalanceRequestBody) GetOwnerID() *OwnerID { return nil } -func (b *BalanceRequestBody) SetOwnerID(v *OwnerID) { +func (b *BalanceRequestBody) SetOwnerID(v *refs.OwnerID) { if b != nil { b.ownerID = v } @@ -56,7 +61,7 @@ func (b *BalanceRequest) SetBody(v *BalanceRequestBody) { } } -func (b *BalanceRequest) GetRequestMetaHeader() *RequestMetaHeader { +func (b *BalanceRequest) GetRequestMetaHeader() *service.RequestMetaHeader { if b != nil { return b.metaHeader } @@ -64,13 +69,13 @@ func (b *BalanceRequest) GetRequestMetaHeader() *RequestMetaHeader { return nil } -func (b *BalanceRequest) SetRequestMetaHeader(v *RequestMetaHeader) { +func (b *BalanceRequest) SetRequestMetaHeader(v *service.RequestMetaHeader) { if b != nil { b.metaHeader = v } } -func (b *BalanceRequest) GetRequestVerificationHeader() *RequestVerificationHeader { +func (b *BalanceRequest) GetRequestVerificationHeader() *service.RequestVerificationHeader { if b != nil { return b.verifyHeader } @@ -78,7 +83,7 @@ func (b *BalanceRequest) GetRequestVerificationHeader() *RequestVerificationHead return nil } -func (b *BalanceRequest) SetRequestVerificationHeader(v *RequestVerificationHeader) { +func (b *BalanceRequest) SetRequestVerificationHeader(v *service.RequestVerificationHeader) { if b != nil { b.verifyHeader = v } diff --git a/v2/accounting/convert.go b/v2/accounting/convert.go new file mode 100644 index 0000000..9f04943 --- /dev/null +++ b/v2/accounting/convert.go @@ -0,0 +1,106 @@ +package accounting + +import ( + accounting "github.com/nspcc-dev/neofs-api-go/v2/accounting/grpc" + "github.com/nspcc-dev/neofs-api-go/v2/refs" + "github.com/nspcc-dev/neofs-api-go/v2/service" + grpcService "github.com/nspcc-dev/neofs-api-go/v2/service/grpc" +) + +func BalanceRequestBodyToGRPCMessage(b *BalanceRequestBody) *accounting.BalanceRequest_Body { + if b == nil { + return nil + } + + m := new(accounting.BalanceRequest_Body) + + m.SetOwnerId( + refs.OwnerIDToGRPCMessage(b.GetOwnerID()), + ) + + return m +} + +func BalanceRequestBodyFromGRPCMessage(m *accounting.BalanceRequest_Body) *BalanceRequestBody { + if m == nil { + return nil + } + + b := new(BalanceRequestBody) + + b.SetOwnerID( + refs.OwnerIDFromGRPCMessage(m.GetOwnerId()), + ) + + return b +} + +func headersToGRPC( + src interface { + GetRequestMetaHeader() *service.RequestMetaHeader + GetRequestVerificationHeader() *service.RequestVerificationHeader + }, + dst interface { + SetMetaHeader(*grpcService.RequestMetaHeader) + SetVerifyHeader(*grpcService.RequestVerificationHeader) + }, +) { + dst.SetMetaHeader( + service.RequestMetaHeaderToGRPCMessage(src.GetRequestMetaHeader()), + ) + + dst.SetVerifyHeader( + service.RequestVerificationHeaderToGRPCMessage(src.GetRequestVerificationHeader()), + ) +} + +func headersFromGRPC( + src interface { + GetMetaHeader() *grpcService.RequestMetaHeader + GetVerifyHeader() *grpcService.RequestVerificationHeader + }, + dst interface { + SetRequestMetaHeader(*service.RequestMetaHeader) + SetRequestVerificationHeader(*service.RequestVerificationHeader) + }, +) { + dst.SetRequestMetaHeader( + service.RequestMetaHeaderFromGRPCMessage(src.GetMetaHeader()), + ) + + dst.SetRequestVerificationHeader( + service.RequestVerificationHeaderFromGRPCMessage(src.GetVerifyHeader()), + ) +} + +func BalanceRequestToGRPCMessage(b *BalanceRequest) *accounting.BalanceRequest { + if b == nil { + return nil + } + + m := new(accounting.BalanceRequest) + + m.SetBody( + BalanceRequestBodyToGRPCMessage(b.GetBody()), + ) + + headersToGRPC(b, m) + + return m +} + +func BalanceRequestFromGRPCMessage(m *accounting.BalanceRequest) *BalanceRequest { + if m == nil { + return nil + } + + b := new(BalanceRequest) + + b.SetBody( + BalanceRequestBodyFromGRPCMessage(m.GetBody()), + ) + + headersFromGRPC(m, b) + + return b +} diff --git a/v2/accounting/service.go b/v2/accounting/grpc/service.go similarity index 92% rename from v2/accounting/service.go rename to v2/accounting/grpc/service.go index 456d0e2..0da7936 100644 --- a/v2/accounting/service.go +++ b/v2/accounting/grpc/service.go @@ -1,8 +1,8 @@ package accounting import ( - "github.com/nspcc-dev/neofs-api-go/v2/refs" - "github.com/nspcc-dev/neofs-api-go/v2/service" + refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc" + service "github.com/nspcc-dev/neofs-api-go/v2/service/grpc" ) // SetValue sets value of the decimal number. diff --git a/v2/accounting/service.pb.go b/v2/accounting/grpc/service.pb.go similarity index 84% rename from v2/accounting/service.pb.go rename to v2/accounting/grpc/service.pb.go index f8a40e8..aa9fdbe 100644 Binary files a/v2/accounting/service.pb.go and b/v2/accounting/grpc/service.pb.go differ diff --git a/v2/acl/types.go b/v2/acl/grpc/types.go similarity index 97% rename from v2/acl/types.go rename to v2/acl/grpc/types.go index 6374787..3091259 100644 --- a/v2/acl/types.go +++ b/v2/acl/grpc/types.go @@ -1,7 +1,7 @@ package acl import ( - "github.com/nspcc-dev/neofs-api-go/v2/refs" + refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc" ) // SetContainerId sets container identifier of the eACL table. diff --git a/v2/acl/types.pb.go b/v2/acl/grpc/types.pb.go similarity index 87% rename from v2/acl/types.pb.go rename to v2/acl/grpc/types.pb.go index 0425329..bba96ad 100644 Binary files a/v2/acl/types.pb.go and b/v2/acl/grpc/types.pb.go differ diff --git a/v2/container/marshal.go b/v2/container/grpc/marshal.go similarity index 100% rename from v2/container/marshal.go rename to v2/container/grpc/marshal.go diff --git a/v2/container/marshal_test.go b/v2/container/grpc/marshal_test.go similarity index 92% rename from v2/container/marshal_test.go rename to v2/container/grpc/marshal_test.go index a7e2888..ef8bfdd 100644 --- a/v2/container/marshal_test.go +++ b/v2/container/grpc/marshal_test.go @@ -3,8 +3,8 @@ package container import ( "testing" - "github.com/nspcc-dev/neofs-api-go/v2/netmap" - "github.com/nspcc-dev/neofs-api-go/v2/refs" + 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" ) diff --git a/v2/container/service.go b/v2/container/grpc/service.go similarity index 97% rename from v2/container/service.go rename to v2/container/grpc/service.go index bde2b48..3cbbe58 100644 --- a/v2/container/service.go +++ b/v2/container/grpc/service.go @@ -1,9 +1,9 @@ package container import ( - "github.com/nspcc-dev/neofs-api-go/v2/acl" - "github.com/nspcc-dev/neofs-api-go/v2/refs" - "github.com/nspcc-dev/neofs-api-go/v2/service" + acl "github.com/nspcc-dev/neofs-api-go/v2/acl/grpc" + refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc" + service "github.com/nspcc-dev/neofs-api-go/v2/service/grpc" ) // SetContainer sets container of the request. diff --git a/v2/container/service.pb.go b/v2/container/grpc/service.pb.go similarity index 88% rename from v2/container/service.pb.go rename to v2/container/grpc/service.pb.go index 50a9347..c5ae473 100644 Binary files a/v2/container/service.pb.go and b/v2/container/grpc/service.pb.go differ diff --git a/v2/container/signature.go b/v2/container/grpc/signature.go similarity index 100% rename from v2/container/signature.go rename to v2/container/grpc/signature.go diff --git a/v2/container/types.go b/v2/container/grpc/types.go similarity index 89% rename from v2/container/types.go rename to v2/container/grpc/types.go index eb74ead..3678b56 100644 --- a/v2/container/types.go +++ b/v2/container/grpc/types.go @@ -1,8 +1,8 @@ package container import ( - "github.com/nspcc-dev/neofs-api-go/v2/netmap" - "github.com/nspcc-dev/neofs-api-go/v2/refs" + netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc" + refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc" ) // SetKey sets key to the container attribute. diff --git a/v2/container/types.pb.go b/v2/container/grpc/types.pb.go similarity index 84% rename from v2/container/types.pb.go rename to v2/container/grpc/types.pb.go index 175aeeb..9cd174d 100644 Binary files a/v2/container/types.pb.go and b/v2/container/grpc/types.pb.go differ diff --git a/v2/convert.go b/v2/convert.go index 8cc95a6..5ec3cc8 100644 --- a/v2/convert.go +++ b/v2/convert.go @@ -1,351 +1 @@ package v2 - -import ( - "github.com/nspcc-dev/neofs-api-go/v2/accounting" - "github.com/nspcc-dev/neofs-api-go/v2/refs" - "github.com/nspcc-dev/neofs-api-go/v2/service" -) - -func SignatureToGRPCMessage(s *Signature) *service.Signature { - if s == nil { - return nil - } - - m := new(service.Signature) - - m.SetKey(s.GetKey()) - m.SetSign(s.GetSign()) - - return m -} - -func SignatureFromGRPCMessage(m *service.Signature) *Signature { - if m == nil { - return nil - } - - s := new(Signature) - - s.SetKey(m.GetKey()) - s.SetSign(m.GetSign()) - - return s -} - -func VersionToGRPCMessage(v *Version) *service.Version { - if v == nil { - return nil - } - - msg := new(service.Version) - - msg.SetMajor(v.GetMajor()) - msg.SetMinor(v.GetMinor()) - - return msg -} - -func VersionFromGRPCMessage(m *service.Version) *Version { - if m == nil { - return nil - } - - v := new(Version) - - v.SetMajor(m.GetMajor()) - v.SetMinor(m.GetMinor()) - - return v -} - -func XHeaderToGRPCMessage(x *XHeader) *service.XHeader { - if x == nil { - return nil - } - - m := new(service.XHeader) - - m.SetKey(x.GetKey()) - m.SetValue(x.GetValue()) - - return m -} - -func XHeaderFromGRPCMessage(m *service.XHeader) *XHeader { - if m == nil { - return nil - } - - x := new(XHeader) - - x.SetKey(m.GetKey()) - x.SetValue(m.GetValue()) - - return x -} - -func SessionTokenToGRPCMessage(t *SessionToken) *service.SessionToken { - // TODO: fill me - return nil -} - -func SessionTokenFromGRPCMessage(m *service.SessionToken) *SessionToken { - // TODO: fill me - return nil -} - -func BearerTokenToGRPCMessage(t *BearerToken) *service.BearerToken { - // TODO: fill me - return nil -} - -func BearerTokenFromGRPCMessage(m *service.BearerToken) *BearerToken { - // TODO: fill me - return nil -} - -func RequestVerificationHeaderToGRPCMessage(r *RequestVerificationHeader) *service.RequestVerificationHeader { - if r == nil { - return nil - } - - m := new(service.RequestVerificationHeader) - - m.SetBodySignature( - SignatureToGRPCMessage(r.GetBodySignature()), - ) - - m.SetMetaSignature( - SignatureToGRPCMessage(r.GetMetaSignature()), - ) - - m.SetOriginSignature( - SignatureToGRPCMessage(r.GetOriginSignature()), - ) - - m.SetOrigin( - RequestVerificationHeaderToGRPCMessage(r.GetOrigin()), - ) - - return m -} - -func RequestVerificationHeaderFromGRPCMessage(m *service.RequestVerificationHeader) *RequestVerificationHeader { - if m == nil { - return nil - } - - r := new(RequestVerificationHeader) - - r.SetBodySignature( - SignatureFromGRPCMessage(m.GetBodySignature()), - ) - - r.SetMetaSignature( - SignatureFromGRPCMessage(m.GetMetaSignature()), - ) - - r.SetOriginSignature( - SignatureFromGRPCMessage(m.GetOriginSignature()), - ) - - r.SetOrigin( - RequestVerificationHeaderFromGRPCMessage(m.GetOrigin()), - ) - - return r -} - -func RequestMetaHeaderToGRPCMessage(r *RequestMetaHeader) *service.RequestMetaHeader { - if r == nil { - return nil - } - - m := new(service.RequestMetaHeader) - - m.SetTtl(r.GetTTL()) - m.SetEpoch(r.GetEpoch()) - - m.SetVersion( - VersionToGRPCMessage(r.GetVersion()), - ) - - m.SetSessionToken( - SessionTokenToGRPCMessage(r.GetSessionToken()), - ) - - m.SetBearerToken( - BearerTokenToGRPCMessage(r.GetBearerToken()), - ) - - m.SetOrigin( - RequestMetaHeaderToGRPCMessage(r.GetOrigin()), - ) - - xHeaders := r.GetXHeaders() - xHdrMsg := make([]*service.XHeader, 0, len(xHeaders)) - - for i := range xHeaders { - xHdrMsg = append(xHdrMsg, XHeaderToGRPCMessage(xHeaders[i])) - } - - return m -} - -func RequestMetaHeaderFromGRPCMessage(m *service.RequestMetaHeader) *RequestMetaHeader { - if m == nil { - return nil - } - - r := new(RequestMetaHeader) - - r.SetTTL(m.GetTtl()) - r.SetEpoch(m.GetEpoch()) - - r.SetVersion( - VersionFromGRPCMessage(m.GetVersion()), - ) - - r.SetSessionToken( - SessionTokenFromGRPCMessage(m.GetSessionToken()), - ) - - r.SetBearerToken( - BearerTokenFromGRPCMessage(m.GetBearerToken()), - ) - - r.SetOrigin( - RequestMetaHeaderFromGRPCMessage(m.GetOrigin()), - ) - - xHdrMsg := m.GetXHeaders() - xHeaders := make([]*XHeader, 0, len(xHdrMsg)) - - for i := range xHdrMsg { - xHeaders = append(xHeaders, XHeaderFromGRPCMessage(xHdrMsg[i])) - } - - return r -} - -func OwnerIDToGRPCMessage(o *OwnerID) *refs.OwnerID { - if o == nil { - return nil - } - - m := new(refs.OwnerID) - - m.SetValue(o.GetValue()) - - return m -} - -func OwnerIDFromGRPCMessage(m *refs.OwnerID) *OwnerID { - if m == nil { - return nil - } - - o := new(OwnerID) - - o.SetValue(m.GetValue()) - - return o -} - -func BalanceRequestBodyToGRPCMessage(b *BalanceRequestBody) *accounting.BalanceRequest_Body { - if b == nil { - return nil - } - - m := new(accounting.BalanceRequest_Body) - - m.SetOwnerId( - OwnerIDToGRPCMessage(b.GetOwnerID()), - ) - - return m -} - -func BalanceRequestBodyFromGRPCMessage(m *accounting.BalanceRequest_Body) *BalanceRequestBody { - if m == nil { - return nil - } - - b := new(BalanceRequestBody) - - b.SetOwnerID( - OwnerIDFromGRPCMessage(m.GetOwnerId()), - ) - - return b -} - -func headersToGRPC( - src interface { - GetRequestMetaHeader() *RequestMetaHeader - GetRequestVerificationHeader() *RequestVerificationHeader - }, - dst interface { - SetMetaHeader(*service.RequestMetaHeader) - SetVerifyHeader(*service.RequestVerificationHeader) - }, -) { - dst.SetMetaHeader( - RequestMetaHeaderToGRPCMessage(src.GetRequestMetaHeader()), - ) - - dst.SetVerifyHeader( - RequestVerificationHeaderToGRPCMessage(src.GetRequestVerificationHeader()), - ) -} - -func headersFromGRPC( - src interface { - GetMetaHeader() *service.RequestMetaHeader - GetVerifyHeader() *service.RequestVerificationHeader - }, - dst interface { - SetRequestMetaHeader(*RequestMetaHeader) - SetRequestVerificationHeader(*RequestVerificationHeader) - }, -) { - dst.SetRequestMetaHeader( - RequestMetaHeaderFromGRPCMessage(src.GetMetaHeader()), - ) - - dst.SetRequestVerificationHeader( - RequestVerificationHeaderFromGRPCMessage(src.GetVerifyHeader()), - ) -} - -func BalanceRequestToGRPCMessage(b *BalanceRequest) *accounting.BalanceRequest { - if b == nil { - return nil - } - - m := new(accounting.BalanceRequest) - - m.SetBody( - BalanceRequestBodyToGRPCMessage(b.GetBody()), - ) - - headersToGRPC(b, m) - - return m -} - -func BalanceRequestFromGRPCMessage(m *accounting.BalanceRequest) *BalanceRequest { - if m == nil { - return nil - } - - b := new(BalanceRequest) - - b.SetBody( - BalanceRequestBodyFromGRPCMessage(m.GetBody()), - ) - - headersFromGRPC(m, b) - - return b -} diff --git a/v2/netmap/marshal.go b/v2/netmap/grpc/marshal.go similarity index 100% rename from v2/netmap/marshal.go rename to v2/netmap/grpc/marshal.go diff --git a/v2/netmap/types.go b/v2/netmap/grpc/types.go similarity index 100% rename from v2/netmap/types.go rename to v2/netmap/grpc/types.go diff --git a/v2/netmap/types.pb.go b/v2/netmap/grpc/types.pb.go similarity index 92% rename from v2/netmap/types.pb.go rename to v2/netmap/grpc/types.pb.go index bfc2e9e..2893490 100644 Binary files a/v2/netmap/types.pb.go and b/v2/netmap/grpc/types.pb.go differ diff --git a/v2/object/service.go b/v2/object/grpc/service.go similarity index 99% rename from v2/object/service.go rename to v2/object/grpc/service.go index eae7ae5..0372b3d 100644 --- a/v2/object/service.go +++ b/v2/object/grpc/service.go @@ -1,8 +1,8 @@ package object import ( - "github.com/nspcc-dev/neofs-api-go/v2/refs" - "github.com/nspcc-dev/neofs-api-go/v2/service" + refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc" + service "github.com/nspcc-dev/neofs-api-go/v2/service/grpc" ) // SetAddress sets address of the requested object. diff --git a/v2/object/service.pb.go b/v2/object/grpc/service.pb.go similarity index 89% rename from v2/object/service.pb.go rename to v2/object/grpc/service.pb.go index 1865e41..a6f18df 100644 Binary files a/v2/object/service.pb.go and b/v2/object/grpc/service.pb.go differ diff --git a/v2/object/types.go b/v2/object/grpc/types.go similarity index 96% rename from v2/object/types.go rename to v2/object/grpc/types.go index 7a97531..c857b8a 100644 --- a/v2/object/types.go +++ b/v2/object/grpc/types.go @@ -1,8 +1,8 @@ package object import ( - "github.com/nspcc-dev/neofs-api-go/v2/refs" - "github.com/nspcc-dev/neofs-api-go/v2/service" + refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc" + service "github.com/nspcc-dev/neofs-api-go/v2/service/grpc" ) // SetKey sets key to the object attribute. diff --git a/v2/object/types.pb.go b/v2/object/grpc/types.pb.go similarity index 86% rename from v2/object/types.pb.go rename to v2/object/grpc/types.pb.go index a3712b5..f4617b0 100644 Binary files a/v2/object/types.pb.go and b/v2/object/grpc/types.pb.go differ diff --git a/v2/refs/convert.go b/v2/refs/convert.go new file mode 100644 index 0000000..869a0e6 --- /dev/null +++ b/v2/refs/convert.go @@ -0,0 +1,29 @@ +package refs + +import ( + refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc" +) + +func OwnerIDToGRPCMessage(o *OwnerID) *refs.OwnerID { + if o == nil { + return nil + } + + m := new(refs.OwnerID) + + m.SetValue(o.GetValue()) + + return m +} + +func OwnerIDFromGRPCMessage(m *refs.OwnerID) *OwnerID { + if m == nil { + return nil + } + + o := new(OwnerID) + + o.SetValue(m.GetValue()) + + return o +} diff --git a/v2/refs/marshal.go b/v2/refs/grpc/marshal.go similarity index 100% rename from v2/refs/marshal.go rename to v2/refs/grpc/marshal.go diff --git a/v2/refs/marshal_test.go b/v2/refs/grpc/marshal_test.go similarity index 100% rename from v2/refs/marshal_test.go rename to v2/refs/grpc/marshal_test.go diff --git a/v2/refs/types.go b/v2/refs/grpc/types.go similarity index 100% rename from v2/refs/types.go rename to v2/refs/grpc/types.go diff --git a/v2/refs/types.pb.go b/v2/refs/grpc/types.pb.go similarity index 91% rename from v2/refs/types.pb.go rename to v2/refs/grpc/types.pb.go index 5e57a4b..7634600 100644 Binary files a/v2/refs/types.pb.go and b/v2/refs/grpc/types.pb.go differ diff --git a/v2/refs/owner.go b/v2/refs/owner.go new file mode 100644 index 0000000..acaa692 --- /dev/null +++ b/v2/refs/owner.go @@ -0,0 +1,19 @@ +package refs + +type OwnerID struct { + val []byte +} + +func (o *OwnerID) GetValue() []byte { + if o != nil { + return o.val + } + + return nil +} + +func (o *OwnerID) SetValue(v []byte) { + if o != nil { + o.val = v + } +} diff --git a/v2/service/convert.go b/v2/service/convert.go new file mode 100644 index 0000000..bf2c3a2 --- /dev/null +++ b/v2/service/convert.go @@ -0,0 +1,201 @@ +package service + +import ( + service "github.com/nspcc-dev/neofs-api-go/v2/service/grpc" +) + +func VersionToGRPCMessage(v *Version) *service.Version { + if v == nil { + return nil + } + + msg := new(service.Version) + + msg.SetMajor(v.GetMajor()) + msg.SetMinor(v.GetMinor()) + + return msg +} + +func VersionFromGRPCMessage(m *service.Version) *Version { + if m == nil { + return nil + } + + v := new(Version) + + v.SetMajor(m.GetMajor()) + v.SetMinor(m.GetMinor()) + + return v +} + +func XHeaderToGRPCMessage(x *XHeader) *service.XHeader { + if x == nil { + return nil + } + + m := new(service.XHeader) + + m.SetKey(x.GetKey()) + m.SetValue(x.GetValue()) + + return m +} + +func XHeaderFromGRPCMessage(m *service.XHeader) *XHeader { + if m == nil { + return nil + } + + x := new(XHeader) + + x.SetKey(m.GetKey()) + x.SetValue(m.GetValue()) + + return x +} + +func SessionTokenToGRPCMessage(t *SessionToken) *service.SessionToken { + // TODO: fill me + return nil +} + +func SessionTokenFromGRPCMessage(m *service.SessionToken) *SessionToken { + // TODO: fill me + return nil +} + +func BearerTokenToGRPCMessage(t *BearerToken) *service.BearerToken { + // TODO: fill me + return nil +} + +func BearerTokenFromGRPCMessage(m *service.BearerToken) *BearerToken { + // TODO: fill me + return nil +} + +func RequestVerificationHeaderToGRPCMessage(r *RequestVerificationHeader) *service.RequestVerificationHeader { + if r == nil { + return nil + } + + m := new(service.RequestVerificationHeader) + + m.SetBodySignature( + SignatureToGRPCMessage(r.GetBodySignature()), + ) + + m.SetMetaSignature( + SignatureToGRPCMessage(r.GetMetaSignature()), + ) + + m.SetOriginSignature( + SignatureToGRPCMessage(r.GetOriginSignature()), + ) + + m.SetOrigin( + RequestVerificationHeaderToGRPCMessage(r.GetOrigin()), + ) + + return m +} + +func RequestVerificationHeaderFromGRPCMessage(m *service.RequestVerificationHeader) *RequestVerificationHeader { + if m == nil { + return nil + } + + r := new(RequestVerificationHeader) + + r.SetBodySignature( + SignatureFromGRPCMessage(m.GetBodySignature()), + ) + + r.SetMetaSignature( + SignatureFromGRPCMessage(m.GetMetaSignature()), + ) + + r.SetOriginSignature( + SignatureFromGRPCMessage(m.GetOriginSignature()), + ) + + r.SetOrigin( + RequestVerificationHeaderFromGRPCMessage(m.GetOrigin()), + ) + + return r +} + +func RequestMetaHeaderToGRPCMessage(r *RequestMetaHeader) *service.RequestMetaHeader { + if r == nil { + return nil + } + + m := new(service.RequestMetaHeader) + + m.SetTtl(r.GetTTL()) + m.SetEpoch(r.GetEpoch()) + + m.SetVersion( + VersionToGRPCMessage(r.GetVersion()), + ) + + m.SetSessionToken( + SessionTokenToGRPCMessage(r.GetSessionToken()), + ) + + m.SetBearerToken( + BearerTokenToGRPCMessage(r.GetBearerToken()), + ) + + m.SetOrigin( + RequestMetaHeaderToGRPCMessage(r.GetOrigin()), + ) + + xHeaders := r.GetXHeaders() + xHdrMsg := make([]*service.XHeader, 0, len(xHeaders)) + + for i := range xHeaders { + xHdrMsg = append(xHdrMsg, XHeaderToGRPCMessage(xHeaders[i])) + } + + return m +} + +func RequestMetaHeaderFromGRPCMessage(m *service.RequestMetaHeader) *RequestMetaHeader { + if m == nil { + return nil + } + + r := new(RequestMetaHeader) + + r.SetTTL(m.GetTtl()) + r.SetEpoch(m.GetEpoch()) + + r.SetVersion( + VersionFromGRPCMessage(m.GetVersion()), + ) + + r.SetSessionToken( + SessionTokenFromGRPCMessage(m.GetSessionToken()), + ) + + r.SetBearerToken( + BearerTokenFromGRPCMessage(m.GetBearerToken()), + ) + + r.SetOrigin( + RequestMetaHeaderFromGRPCMessage(m.GetOrigin()), + ) + + xHdrMsg := m.GetXHeaders() + xHeaders := make([]*XHeader, 0, len(xHdrMsg)) + + for i := range xHdrMsg { + xHeaders = append(xHeaders, XHeaderFromGRPCMessage(xHdrMsg[i])) + } + + return r +} diff --git a/v2/service/meta.go b/v2/service/grpc/meta.go similarity index 97% rename from v2/service/meta.go rename to v2/service/grpc/meta.go index a44e464..c5e9c78 100644 --- a/v2/service/meta.go +++ b/v2/service/grpc/meta.go @@ -1,8 +1,8 @@ package service import ( - "github.com/nspcc-dev/neofs-api-go/v2/acl" - "github.com/nspcc-dev/neofs-api-go/v2/refs" + acl "github.com/nspcc-dev/neofs-api-go/v2/acl/grpc" + refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc" ) // SetKey sets key to the X-Header. diff --git a/v2/service/meta.pb.go b/v2/service/grpc/meta.pb.go similarity index 91% rename from v2/service/meta.pb.go rename to v2/service/grpc/meta.pb.go index 648f7f0..397dc3a 100644 Binary files a/v2/service/meta.pb.go and b/v2/service/grpc/meta.pb.go differ diff --git a/v2/service/verify.go b/v2/service/grpc/verify.go similarity index 100% rename from v2/service/verify.go rename to v2/service/grpc/verify.go diff --git a/v2/service/verify.pb.go b/v2/service/grpc/verify.pb.go similarity index 91% rename from v2/service/verify.pb.go rename to v2/service/grpc/verify.pb.go index 39a512b..3f270b6 100644 Binary files a/v2/service/verify.pb.go and b/v2/service/grpc/verify.pb.go differ diff --git a/v2/service/version.go b/v2/service/grpc/version.go similarity index 100% rename from v2/service/version.go rename to v2/service/grpc/version.go diff --git a/v2/service.go b/v2/service/service.go similarity index 91% rename from v2/service.go rename to v2/service/service.go index 55a3947..39557ee 100644 --- a/v2/service.go +++ b/v2/service/service.go @@ -1,4 +1,8 @@ -package v2 +package service + +import ( + service "github.com/nspcc-dev/neofs-api-go/v2/service/grpc" +) type Signature struct { key, sign []byte @@ -42,10 +46,6 @@ type RequestMetaHeader struct { origin *RequestMetaHeader } -type OwnerID struct { - val []byte -} - func (s *Signature) GetKey() []byte { if s != nil { return s.key @@ -316,16 +316,28 @@ func (r *RequestMetaHeader) StableSize() int { return RequestMetaHeaderToGRPCMessage(r).Size() } -func (o *OwnerID) GetValue() []byte { - if o != nil { - return o.val +func SignatureToGRPCMessage(s *Signature) *service.Signature { + if s == nil { + return nil } - return nil + m := new(service.Signature) + + m.SetKey(s.GetKey()) + m.SetSign(s.GetSign()) + + return m } -func (o *OwnerID) SetValue(v []byte) { - if o != nil { - o.val = v +func SignatureFromGRPCMessage(m *service.Signature) *Signature { + if m == nil { + return nil } + + s := new(Signature) + + s.SetKey(m.GetKey()) + s.SetSign(m.GetSign()) + + return s } diff --git a/v2/session/service.go b/v2/session/grpc/service.go similarity index 93% rename from v2/session/service.go rename to v2/session/grpc/service.go index 41a050d..8c78648 100644 --- a/v2/session/service.go +++ b/v2/session/grpc/service.go @@ -1,8 +1,8 @@ package session import ( - "github.com/nspcc-dev/neofs-api-go/v2/refs" - "github.com/nspcc-dev/neofs-api-go/v2/service" + refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc" + service "github.com/nspcc-dev/neofs-api-go/v2/service/grpc" ) // SetOwnerId sets identifier of the session initiator. diff --git a/v2/session/service.pb.go b/v2/session/grpc/service.pb.go similarity index 83% rename from v2/session/service.pb.go rename to v2/session/grpc/service.pb.go index 13b8ad5..7dd61a3 100644 Binary files a/v2/session/service.pb.go and b/v2/session/grpc/service.pb.go differ diff --git a/v2/signature/sign.go b/v2/signature/sign.go index 79fef30..d2fd149 100644 --- a/v2/signature/sign.go +++ b/v2/signature/sign.go @@ -5,14 +5,15 @@ import ( "fmt" "github.com/nspcc-dev/neofs-api-go/util/signature" - v2 "github.com/nspcc-dev/neofs-api-go/v2" + "github.com/nspcc-dev/neofs-api-go/v2/accounting" + "github.com/nspcc-dev/neofs-api-go/v2/service" "github.com/pkg/errors" ) type SignedRequest interface { - GetRequestMetaHeader() *v2.RequestMetaHeader - GetRequestVerificationHeader() *v2.RequestVerificationHeader - SetRequestVerificationHeader(*v2.RequestVerificationHeader) + GetRequestMetaHeader() *service.RequestMetaHeader + GetRequestVerificationHeader() *service.RequestVerificationHeader + SetRequestVerificationHeader(*service.RequestVerificationHeader) } type stableMarshaler interface { @@ -32,14 +33,14 @@ func (s stableMarshalerWrapper) SignedDataSize() int { return s.sm.StableSize() } -func keySignatureHandler(s *v2.Signature) signature.KeySignatureHandler { +func keySignatureHandler(s *service.Signature) signature.KeySignatureHandler { return func(key []byte, sig []byte) { s.SetKey(key) s.SetSign(sig) } } -func keySignatureSource(s *v2.Signature) signature.KeySignatureSource { +func keySignatureSource(s *service.Signature) signature.KeySignatureSource { return func() ([]byte, []byte) { return s.GetKey(), s.GetSign() } @@ -47,7 +48,7 @@ func keySignatureSource(s *v2.Signature) signature.KeySignatureSource { func requestBody(req SignedRequest) stableMarshaler { switch v := req.(type) { - case *v2.BalanceRequest: + case *accounting.BalanceRequest: return v.GetBody() default: panic(fmt.Sprintf("unknown request %T", req)) @@ -60,7 +61,7 @@ func SignRequest(key *ecdsa.PrivateKey, req SignedRequest) error { } // create new level of matryoshka - verifyHdr := new(v2.RequestVerificationHeader) + verifyHdr := new(service.RequestVerificationHeader) // attach the previous matryoshka verifyHdr.SetOrigin(req.GetRequestVerificationHeader()) @@ -86,8 +87,8 @@ func SignRequest(key *ecdsa.PrivateKey, req SignedRequest) error { return nil } -func signRequestPart(key *ecdsa.PrivateKey, part stableMarshaler, sigWrite func(*v2.Signature)) error { - sig := new(v2.Signature) +func signRequestPart(key *ecdsa.PrivateKey, part stableMarshaler, sigWrite func(*service.Signature)) error { + sig := new(service.Signature) // sign part if err := signature.SignDataWithHandler( @@ -125,7 +126,7 @@ func VerifyRequest(req SignedRequest) error { return nil } -func verifyRequestPart(part stableMarshaler, sigRdr func() *v2.Signature) error { +func verifyRequestPart(part stableMarshaler, sigRdr func() *service.Signature) error { if err := signature.VerifyDataWithSource( &stableMarshalerWrapper{part}, keySignatureSource(sigRdr()), diff --git a/v2/storagegroup/types.go b/v2/storagegroup/grpc/types.go similarity index 93% rename from v2/storagegroup/types.go rename to v2/storagegroup/grpc/types.go index 5f4bd37..b1159c4 100644 --- a/v2/storagegroup/types.go +++ b/v2/storagegroup/grpc/types.go @@ -1,7 +1,7 @@ package storagegroup import ( - "github.com/nspcc-dev/neofs-api-go/v2/refs" + refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc" ) // SetValidationDataSize sets the total size of the payloads of the storage group. diff --git a/v2/storagegroup/types.pb.go b/v2/storagegroup/grpc/types.pb.go similarity index 82% rename from v2/storagegroup/types.pb.go rename to v2/storagegroup/grpc/types.pb.go index 2622367..91dae60 100644 Binary files a/v2/storagegroup/types.pb.go and b/v2/storagegroup/grpc/types.pb.go differ