From 9789b79b1d779d478586cb722955e61bc08b705d Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Tue, 28 May 2024 11:04:07 +0300 Subject: [PATCH] [#85] apemanager: Generate protobufs for `ape` package * Regenerate protobufs as APE specific type are defined as separate package; * Move `ape` package related utils methods from `apemanager`. Signed-off-by: Airat Arifullin --- ape/convert.go | 132 +++++++++++++++++++++++ {apemanager => ape}/grpc/types.go | 2 +- {apemanager => ape}/grpc/types.pb.go | Bin 9919 -> 9385 bytes {apemanager => ape}/json.go | 6 +- ape/marshal.go | 92 ++++++++++++++++ ape/message_test.go | 15 +++ {apemanager => ape}/string.go | 6 +- ape/test/generate.go | 71 +++++++++++++ ape/types.go | 71 +++++++++++++ apemanager/convert.go | 151 +++------------------------ apemanager/grpc/service.go | 37 +++---- apemanager/grpc/service.pb.go | Bin 46612 -> 46394 bytes apemanager/marshal.go | 83 --------------- apemanager/message_test.go | 1 - apemanager/test/generate.go | 77 ++------------ apemanager/types.go | 101 +++--------------- 16 files changed, 443 insertions(+), 402 deletions(-) create mode 100644 ape/convert.go rename {apemanager => ape}/grpc/types.go (94%) rename {apemanager => ape}/grpc/types.pb.go (51%) rename {apemanager => ape}/json.go (56%) create mode 100644 ape/marshal.go create mode 100644 ape/message_test.go rename {apemanager => ape}/string.go (56%) create mode 100644 ape/test/generate.go create mode 100644 ape/types.go diff --git a/ape/convert.go b/ape/convert.go new file mode 100644 index 0000000..c1dadd5 --- /dev/null +++ b/ape/convert.go @@ -0,0 +1,132 @@ +package ape + +import ( + "fmt" + + ape "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape/grpc" + "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc" + "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" +) + +func TargetTypeToGRPCField(typ TargetType) ape.TargetType { + switch typ { + case TargetTypeNamespace: + return ape.TargetType_NAMESPACE + case TargetTypeContainer: + return ape.TargetType_CONTAINER + case TargetTypeUser: + return ape.TargetType_USER + case TargetTypeGroup: + return ape.TargetType_GROUP + default: + return ape.TargetType_UNDEFINED + } +} + +func TargetTypeFromGRPCField(typ ape.TargetType) TargetType { + switch typ { + case ape.TargetType_NAMESPACE: + return TargetTypeNamespace + case ape.TargetType_CONTAINER: + return TargetTypeContainer + case ape.TargetType_USER: + return TargetTypeUser + case ape.TargetType_GROUP: + return TargetTypeGroup + default: + return TargetTypeUndefined + } +} + +func TargetTypeToGRPC(typ TargetType) ape.TargetType { + return ape.TargetType(typ) +} + +func TargetTypeFromGRPC(typ ape.TargetType) TargetType { + return TargetType(typ) +} + +func (v2 *ChainTarget) ToGRPCMessage() grpc.Message { + var mgrpc *ape.ChainTarget + + if v2 != nil { + mgrpc = new(ape.ChainTarget) + + mgrpc.SetType(TargetTypeToGRPC(v2.GetTargetType())) + mgrpc.SetName(v2.GetName()) + } + + return mgrpc +} + +func (v2 *ChainTarget) FromGRPCMessage(m grpc.Message) error { + mgrpc, ok := m.(*ape.ChainTarget) + if !ok { + return message.NewUnexpectedMessageType(m, mgrpc) + } + + v2.SetTargetType(TargetTypeFromGRPC(mgrpc.GetType())) + v2.SetName(mgrpc.GetName()) + + return nil +} + +func (v2 *ChainRaw) ToGRPCMessage() grpc.Message { + var mgrpc *ape.Chain_Raw + + if v2 != nil { + mgrpc = new(ape.Chain_Raw) + + mgrpc.SetRaw(v2.GetRaw()) + } + + return mgrpc +} + +func (v2 *ChainRaw) FromGRPCMessage(m grpc.Message) error { + mgrpc, ok := m.(*ape.Chain_Raw) + if !ok { + return message.NewUnexpectedMessageType(m, mgrpc) + } + + v2.SetRaw(mgrpc.GetRaw()) + + return nil +} + +func (v2 *Chain) ToGRPCMessage() grpc.Message { + var mgrpc *ape.Chain + + if v2 != nil { + mgrpc = new(ape.Chain) + + switch chainKind := v2.GetKind().(type) { + default: + panic(fmt.Sprintf("unsupported chain kind: %T", chainKind)) + case *ChainRaw: + mgrpc.SetKind(chainKind.ToGRPCMessage().(*ape.Chain_Raw)) + } + } + + return mgrpc +} + +func (v2 *Chain) FromGRPCMessage(m grpc.Message) error { + mgrpc, ok := m.(*ape.Chain) + if !ok { + return message.NewUnexpectedMessageType(m, mgrpc) + } + + switch chainKind := mgrpc.GetKind().(type) { + default: + return fmt.Errorf("unsupported chain kind: %T", chainKind) + case *ape.Chain_Raw: + chainRaw := new(ChainRaw) + if err := chainRaw.FromGRPCMessage(chainKind); err != nil { + return err + } + v2.SetKind(chainRaw) + } + + return nil +} diff --git a/apemanager/grpc/types.go b/ape/grpc/types.go similarity index 94% rename from apemanager/grpc/types.go rename to ape/grpc/types.go index 0f2ebb2..931b6a3 100644 --- a/apemanager/grpc/types.go +++ b/ape/grpc/types.go @@ -1,4 +1,4 @@ -package apemanager +package ape func (t *ChainTarget) SetType(typ TargetType) { t.Type = typ diff --git a/apemanager/grpc/types.pb.go b/ape/grpc/types.pb.go similarity index 51% rename from apemanager/grpc/types.pb.go rename to ape/grpc/types.pb.go index 395857ae3e8c932354da9903f799ef941a39ab43..1da2110dba8d164f67e9a55694880140fadd5dbd 100644 GIT binary patch delta 779 zcmX9+O=uHQ5N2bm$(lB4yT93=Y^qJIO=Yu5Hm%}e5h)(TinRw3B$PyjDs7QkP*G1_ zL@Xa3R74a+#2#95>On<3dJr!nh@j}Pptc7Of;#i|@aB6n-}mOtdo!;NKRa~$+R_bo zb@^`xRy*ftxftL25fgSE!|Cq!v2B`!+2kkO++krw?m!~D7td4Q*l(}M$0b&_htpFD zia6~j-CdH{e8`N))PbHi61w{K;iqNdOrI)MF{^0ET5cj}!Bg$ddZi?%@UO2V`8clz z3348(IxZ@iWDt}*f3a4^no{QYJKal`MJ#ASQR}Xp@)!Lwi-J+Mev@rQNXiYoGzV}? zb@}LwlEa2Nh;_XeB`wV%TP@&(=1CqdYYqqQX%RV}W9N?+;h@@!Bf1cu)R}vz3*ier zq9iFK4VBNi26GKVa9528EklzlTuHUXZ~J0I9v9aTC05ziYQn~%8jB(`+RcQ|L|Is0 zNUP#Cl_rUZ7C9=@ST^hQG%d^+4<&+ZLgR?{c%gqAR~2NAn}eJ(G?3)6EN$ zc%3g{Ex&=Uo{6_!hHwy>!UPW>t`{~5UEJ+oC;TBQy1#Rg5}T+D-(1p=+FJE;N$y%}ktm2AS`-%tTRk>iQCKV z7oCbTTVA-ctkumYD_gB~8@j?8thSwK;Gbkyqy6q+yV63ABOUMRwwvM(1c4NnbgxH_ z2M$*HqjNG;PlpsIyHnjgK?ZZ&>KP}8TaA7ufTuf0sk9muABgd! z!?WCA+h`ZrX`6Q?F%;q8C_m7m!)1P`Glv1o8uGmBLJ>ala(?{sL zNXT_lf7@hoB|!@1i!deFninx}GIQ9Acz^@uvDnPPhs1u^5V%83us%9VvyEW(Z9`En zt7#_aitTP=rA2UJy{$#B1DuSN*q!gkRPWBueE5wZ#W8X!&LY=*SVMU4gVxI;W4)Mm z17XF7PY8c}C?#0hnM7$2TjSI@JdFaoK>;sXIETA((Br_Xgsro5Z}(n`oo8q5_9M); zyiGt_ENPhJ>!3pI8~e+ffd~9Pcq|I2W%`f6U&#zA;%R$5;ESmD|96Y58G9z9HK~8U zCqEM>#Ze3kuJUOpOL2OkhOELpNg!q~c1doB*HTB5@2j+%hJh34c$oA`ZHSu#< zYT`{f=+_mNL09%rJjF>cs~E)783kNrgm^=-$WE(vU+q6)@8Jv1TqUv;x#BG7GjsFh z)6S)GEd~{JjA|aK)XROVW`m#YmKF@XrHODb*-b?g$zx=vI2Bftn++_(OZ|HjS5t3@ z*+SORi^S6z5hnYR#1&P9n+?nsvfjXKA;0>957v{(QZ3V-%tVQ&GXrE-R3%)QoA*}o E7sbw!V*mgE diff --git a/apemanager/json.go b/ape/json.go similarity index 56% rename from apemanager/json.go rename to ape/json.go index 4f44d5e..9760f4e 100644 --- a/apemanager/json.go +++ b/ape/json.go @@ -1,7 +1,7 @@ -package apemanager +package ape import ( - apemanager_grpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager/grpc" + ape "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape/grpc" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" ) @@ -10,5 +10,5 @@ func (t *ChainTarget) MarshalJSON() ([]byte, error) { } func (t *ChainTarget) UnmarshalJSON(data []byte) error { - return message.UnmarshalJSON(t, data, new(apemanager_grpc.ChainTarget)) + return message.UnmarshalJSON(t, data, new(ape.ChainTarget)) } diff --git a/ape/marshal.go b/ape/marshal.go new file mode 100644 index 0000000..9889261 --- /dev/null +++ b/ape/marshal.go @@ -0,0 +1,92 @@ +package ape + +import ( + "fmt" + + ape "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape/grpc" + "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" + "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto" +) + +const ( + chainTargetTargetTypeField = 1 + chainTargetNameField = 2 + + chainRawField = 1 +) + +func (t *ChainTarget) StableSize() (size int) { + if t == nil { + return 0 + } + + size += proto.EnumSize(chainTargetTargetTypeField, int32(t.targeType)) + size += proto.StringSize(chainTargetNameField, t.name) + + return size +} + +func (t *ChainTarget) StableMarshal(buf []byte) []byte { + if t == nil { + return []byte{} + } + + if buf == nil { + buf = make([]byte, t.StableSize()) + } + + var offset int + + offset += proto.EnumMarshal(chainTargetTargetTypeField, buf[offset:], int32(t.targeType)) + proto.StringMarshal(chainTargetNameField, buf[offset:], t.name) + + return buf +} + +func (t *ChainTarget) Unmarshal(data []byte) error { + return message.Unmarshal(t, data, new(ape.ChainTarget)) +} + +func (c *Chain) StableSize() (size int) { + if c == nil { + return 0 + } + + switch v := c.GetKind().(type) { + case *ChainRaw: + if v != nil { + size += proto.BytesSize(chainRawField, v.GetRaw()) + } + default: + panic(fmt.Sprintf("unsupported chain kind: %T", v)) + } + + return size +} + +func (c *Chain) StableMarshal(buf []byte) []byte { + if c == nil { + return []byte{} + } + + if buf == nil { + buf = make([]byte, c.StableSize()) + } + + var offset int + + switch v := c.GetKind().(type) { + case *ChainRaw: + if v != nil { + proto.BytesMarshal(chainRawField, buf[offset:], v.GetRaw()) + } + default: + panic(fmt.Sprintf("unsupported chain kind: %T", v)) + } + + return buf +} + +func (c *Chain) Unmarshal(data []byte) error { + return message.Unmarshal(c, data, new(ape.Chain)) +} diff --git a/ape/message_test.go b/ape/message_test.go new file mode 100644 index 0000000..636a521 --- /dev/null +++ b/ape/message_test.go @@ -0,0 +1,15 @@ +package ape_test + +import ( + "testing" + + apetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape/test" + "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" + messagetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message/test" +) + +func TestMessageConvert(t *testing.T) { + messagetest.TestRPCMessage(t, + func(empty bool) message.Message { return apetest.GenerateChainTarget(empty) }, + ) +} diff --git a/apemanager/string.go b/ape/string.go similarity index 56% rename from apemanager/string.go rename to ape/string.go index dddeede..2e2507e 100644 --- a/apemanager/string.go +++ b/ape/string.go @@ -1,7 +1,7 @@ -package apemanager +package ape import ( - apemanager_grpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager/grpc" + apegrpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape/grpc" ) func (tt TargetType) String() string { @@ -9,7 +9,7 @@ func (tt TargetType) String() string { } func (tt *TargetType) FromString(s string) bool { - i, ok := apemanager_grpc.TargetType_value[s] + i, ok := apegrpc.TargetType_value[s] if ok { *tt = TargetType(i) } diff --git a/ape/test/generate.go b/ape/test/generate.go new file mode 100644 index 0000000..9caf9de --- /dev/null +++ b/ape/test/generate.go @@ -0,0 +1,71 @@ +package test + +import ( + "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape" +) + +func GenerateRawChains(empty bool, n int) []*ape.Chain { + if empty { + return []*ape.Chain{} + } + + res := make([]*ape.Chain, n) + for i := range res { + res[i] = GenerateRawChain(empty) + } + return res +} + +func GenerateRawChain(empty bool) *ape.Chain { + chRaw := new(ape.ChainRaw) + + if empty { + chRaw.SetRaw([]byte("{}")) + } else { + chRaw.SetRaw([]byte(`{ + "ID": "", + "Rules": [ + { + "Status": "Allow", + "Actions": { + "Inverted": false, + "Names": [ + "GetObject" + ] + }, + "Resources": { + "Inverted": false, + "Names": [ + "native:object/*" + ] + }, + "Any": false, + "Condition": [ + { + "Op": "StringEquals", + "Object": "Resource", + "Key": "Department", + "Value": "HR" + } + ] + } + ], + "MatchType": "DenyPriority" + }`)) + } + + ch := new(ape.Chain) + ch.SetKind(chRaw) + return ch +} + +func GenerateChainTarget(empty bool) *ape.ChainTarget { + m := new(ape.ChainTarget) + + if !empty { + m.SetTargetType(ape.TargetTypeContainer) + m.SetName("BzQw5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R") + } + + return m +} diff --git a/ape/types.go b/ape/types.go new file mode 100644 index 0000000..935a5ea --- /dev/null +++ b/ape/types.go @@ -0,0 +1,71 @@ +package ape + +type TargetType uint32 + +const ( + TargetTypeUndefined TargetType = iota + TargetTypeNamespace + TargetTypeContainer + TargetTypeUser + TargetTypeGroup +) + +type ChainTarget struct { + targeType TargetType + + name string +} + +func (ct *ChainTarget) SetTargetType(targeType TargetType) { + ct.targeType = targeType +} + +func (ct *ChainTarget) SetName(name string) { + ct.name = name +} + +func (ct *ChainTarget) GetTargetType() TargetType { + if ct != nil { + return ct.targeType + } + + return 0 +} + +func (ct *ChainTarget) GetName() string { + if ct != nil { + return ct.name + } + + return "" +} + +type chainKind interface { + isChainKind() +} + +type Chain struct { + kind chainKind +} + +func (c *Chain) SetKind(kind chainKind) { + c.kind = kind +} + +func (c *Chain) GetKind() chainKind { + return c.kind +} + +type ChainRaw struct { + Raw []byte +} + +func (*ChainRaw) isChainKind() {} + +func (c *ChainRaw) SetRaw(raw []byte) { + c.Raw = raw +} + +func (c *ChainRaw) GetRaw() []byte { + return c.Raw +} diff --git a/apemanager/convert.go b/apemanager/convert.go index f1cbcda..fdc5132 100644 --- a/apemanager/convert.go +++ b/apemanager/convert.go @@ -1,144 +1,21 @@ package apemanager import ( - "fmt" - + ape "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape" + apeGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape/grpc" apemanager "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager/grpc" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" ) -func TargetTypeToGRPCField(typ TargetType) apemanager.TargetType { - switch typ { - case TargetTypeNamespace: - return apemanager.TargetType_NAMESPACE - case TargetTypeContainer: - return apemanager.TargetType_CONTAINER - case TargetTypeUser: - return apemanager.TargetType_USER - case TargetTypeGroup: - return apemanager.TargetType_GROUP - default: - return apemanager.TargetType_UNDEFINED - } -} - -func TargetTypeFromGRPCField(typ apemanager.TargetType) TargetType { - switch typ { - case apemanager.TargetType_NAMESPACE: - return TargetTypeNamespace - case apemanager.TargetType_CONTAINER: - return TargetTypeContainer - case apemanager.TargetType_USER: - return TargetTypeUser - case apemanager.TargetType_GROUP: - return TargetTypeGroup - default: - return TargetTypeUndefined - } -} - -func TargetTypeToGRPC(typ TargetType) apemanager.TargetType { - return apemanager.TargetType(typ) -} - -func TargetTypeFromGRPC(typ apemanager.TargetType) TargetType { - return TargetType(typ) -} - -func (v2 *ChainTarget) ToGRPCMessage() grpc.Message { - var mgrpc *apemanager.ChainTarget - - if v2 != nil { - mgrpc = new(apemanager.ChainTarget) - - mgrpc.SetType(TargetTypeToGRPC(v2.GetTargetType())) - mgrpc.SetName(v2.GetName()) - } - - return mgrpc -} - -func (v2 *ChainTarget) FromGRPCMessage(m grpc.Message) error { - mgrpc, ok := m.(*apemanager.ChainTarget) - if !ok { - return message.NewUnexpectedMessageType(m, mgrpc) - } - - v2.SetTargetType(TargetTypeFromGRPC(mgrpc.GetType())) - v2.SetName(mgrpc.GetName()) - - return nil -} - -func (v2 *ChainRaw) ToGRPCMessage() grpc.Message { - var mgrpc *apemanager.Chain_Raw - - if v2 != nil { - mgrpc = new(apemanager.Chain_Raw) - - mgrpc.SetRaw(v2.GetRaw()) - } - - return mgrpc -} - -func (v2 *ChainRaw) FromGRPCMessage(m grpc.Message) error { - mgrpc, ok := m.(*apemanager.Chain_Raw) - if !ok { - return message.NewUnexpectedMessageType(m, mgrpc) - } - - v2.SetRaw(mgrpc.GetRaw()) - - return nil -} - -func (v2 *Chain) ToGRPCMessage() grpc.Message { - var mgrpc *apemanager.Chain - - if v2 != nil { - mgrpc = new(apemanager.Chain) - - switch chainKind := v2.GetKind().(type) { - default: - panic(fmt.Sprintf("unsupported chain kind: %T", chainKind)) - case *ChainRaw: - mgrpc.SetKind(chainKind.ToGRPCMessage().(*apemanager.Chain_Raw)) - } - } - - return mgrpc -} - -func (v2 *Chain) FromGRPCMessage(m grpc.Message) error { - mgrpc, ok := m.(*apemanager.Chain) - if !ok { - return message.NewUnexpectedMessageType(m, mgrpc) - } - - switch chainKind := mgrpc.GetKind().(type) { - default: - return fmt.Errorf("unsupported chain kind: %T", chainKind) - case *apemanager.Chain_Raw: - chainRaw := new(ChainRaw) - if err := chainRaw.FromGRPCMessage(chainKind); err != nil { - return err - } - v2.SetKind(chainRaw) - } - - return nil -} - func (reqBody *AddChainRequestBody) ToGRPCMessage() grpc.Message { var reqBodygrpc *apemanager.AddChainRequest_Body if reqBody != nil { reqBodygrpc = new(apemanager.AddChainRequest_Body) - reqBodygrpc.SetTarget(reqBody.GetTarget().ToGRPCMessage().(*apemanager.ChainTarget)) - reqBodygrpc.SetChain(reqBody.GetChain().ToGRPCMessage().(*apemanager.Chain)) + reqBodygrpc.SetTarget(reqBody.GetTarget().ToGRPCMessage().(*apeGRPC.ChainTarget)) + reqBodygrpc.SetChain(reqBody.GetChain().ToGRPCMessage().(*apeGRPC.Chain)) } return reqBodygrpc @@ -151,14 +28,14 @@ func (reqBody *AddChainRequestBody) FromGRPCMessage(m grpc.Message) error { } if targetgrpc := reqBodygrpc.GetTarget(); targetgrpc != nil { - reqBody.target = new(ChainTarget) + reqBody.target = new(ape.ChainTarget) if err := reqBody.target.FromGRPCMessage(targetgrpc); err != nil { return err } } if chaingrpc := reqBodygrpc.GetChain(); chaingrpc != nil { - reqBody.chain = new(Chain) + reqBody.chain = new(ape.Chain) if err := reqBody.GetChain().FromGRPCMessage(chaingrpc); err != nil { return err } @@ -254,7 +131,7 @@ func (reqBody *RemoveChainRequestBody) ToGRPCMessage() grpc.Message { if reqBody != nil { reqBodygrpc = new(apemanager.RemoveChainRequest_Body) - reqBodygrpc.SetTarget(reqBody.target.ToGRPCMessage().(*apemanager.ChainTarget)) + reqBodygrpc.SetTarget(reqBody.target.ToGRPCMessage().(*apeGRPC.ChainTarget)) reqBodygrpc.SetChainId(reqBody.GetChainID()) } @@ -268,7 +145,7 @@ func (reqBody *RemoveChainRequestBody) FromGRPCMessage(m grpc.Message) error { } if targetgrpc := reqBodygrpc.GetTarget(); targetgrpc != nil { - reqBody.target = new(ChainTarget) + reqBody.target = new(ape.ChainTarget) if err := reqBody.target.FromGRPCMessage(targetgrpc); err != nil { return err } @@ -362,7 +239,7 @@ func (reqBody *ListChainsRequestBody) ToGRPCMessage() grpc.Message { if reqBody != nil { reqBodygrpc = new(apemanager.ListChainsRequest_Body) - reqBodygrpc.SetTarget(reqBody.target.ToGRPCMessage().(*apemanager.ChainTarget)) + reqBodygrpc.SetTarget(reqBody.target.ToGRPCMessage().(*apeGRPC.ChainTarget)) } return reqBodygrpc @@ -375,7 +252,7 @@ func (reqBody *ListChainsRequestBody) FromGRPCMessage(m grpc.Message) error { } if targetgrpc := reqBodygrpc.GetTarget(); targetgrpc != nil { - reqBody.target = new(ChainTarget) + reqBody.target = new(ape.ChainTarget) if err := reqBody.target.FromGRPCMessage(targetgrpc); err != nil { return err } @@ -419,9 +296,9 @@ func (respBody *ListChainsResponseBody) ToGRPCMessage() grpc.Message { if respBody != nil { respBodygrpc = new(apemanager.ListChainsResponse_Body) - chainsgrpc := make([]*apemanager.Chain, 0, len(respBody.GetChains())) + chainsgrpc := make([]*apeGRPC.Chain, 0, len(respBody.GetChains())) for _, chain := range respBody.GetChains() { - chainsgrpc = append(chainsgrpc, chain.ToGRPCMessage().(*apemanager.Chain)) + chainsgrpc = append(chainsgrpc, chain.ToGRPCMessage().(*apeGRPC.Chain)) } respBodygrpc.SetChains(chainsgrpc) @@ -436,10 +313,10 @@ func (respBody *ListChainsResponseBody) FromGRPCMessage(m grpc.Message) error { return message.NewUnexpectedMessageType(m, respBodygrpc) } - chains := make([]*Chain, 0, len(respBodygrpc.GetChains())) + chains := make([]*ape.Chain, 0, len(respBodygrpc.GetChains())) for _, chaingrpc := range respBodygrpc.GetChains() { - chain := new(Chain) + chain := new(ape.Chain) if err := chain.FromGRPCMessage(chaingrpc); err != nil { return err } diff --git a/apemanager/grpc/service.go b/apemanager/grpc/service.go index c07bceb..bd77db0 100644 --- a/apemanager/grpc/service.go +++ b/apemanager/grpc/service.go @@ -1,14 +1,15 @@ package apemanager import ( - session_grpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" + ape "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape/grpc" + session "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc" ) -func (rb *AddChainRequest_Body) SetTarget(t *ChainTarget) { +func (rb *AddChainRequest_Body) SetTarget(t *ape.ChainTarget) { rb.Target = t } -func (rb *AddChainRequest_Body) SetChain(chain *Chain) { +func (rb *AddChainRequest_Body) SetChain(chain *ape.Chain) { rb.Chain = chain } @@ -16,11 +17,11 @@ func (r *AddChainRequest) SetBody(rb *AddChainRequest_Body) { r.Body = rb } -func (r *AddChainRequest) SetMetaHeader(mh *session_grpc.RequestMetaHeader) { +func (r *AddChainRequest) SetMetaHeader(mh *session.RequestMetaHeader) { r.MetaHeader = mh } -func (r *AddChainRequest) SetVerifyHeader(vh *session_grpc.RequestVerificationHeader) { +func (r *AddChainRequest) SetVerifyHeader(vh *session.RequestVerificationHeader) { r.VerifyHeader = vh } @@ -32,15 +33,15 @@ func (r *AddChainResponse) SetBody(rb *AddChainResponse_Body) { r.Body = rb } -func (r *AddChainResponse) SetMetaHeader(mh *session_grpc.ResponseMetaHeader) { +func (r *AddChainResponse) SetMetaHeader(mh *session.ResponseMetaHeader) { r.MetaHeader = mh } -func (r *AddChainResponse) SetVerifyHeader(vh *session_grpc.ResponseVerificationHeader) { +func (r *AddChainResponse) SetVerifyHeader(vh *session.ResponseVerificationHeader) { r.VerifyHeader = vh } -func (rb *RemoveChainRequest_Body) SetTarget(t *ChainTarget) { +func (rb *RemoveChainRequest_Body) SetTarget(t *ape.ChainTarget) { rb.Target = t } @@ -52,11 +53,11 @@ func (r *RemoveChainRequest) SetBody(rb *RemoveChainRequest_Body) { r.Body = rb } -func (r *RemoveChainRequest) SetMetaHeader(mh *session_grpc.RequestMetaHeader) { +func (r *RemoveChainRequest) SetMetaHeader(mh *session.RequestMetaHeader) { r.MetaHeader = mh } -func (r *RemoveChainRequest) SetVerifyHeader(vh *session_grpc.RequestVerificationHeader) { +func (r *RemoveChainRequest) SetVerifyHeader(vh *session.RequestVerificationHeader) { r.VerifyHeader = vh } @@ -64,15 +65,15 @@ func (r *RemoveChainResponse) SetBody(rb *RemoveChainResponse_Body) { r.Body = rb } -func (r *RemoveChainResponse) SetMetaHeader(mh *session_grpc.ResponseMetaHeader) { +func (r *RemoveChainResponse) SetMetaHeader(mh *session.ResponseMetaHeader) { r.MetaHeader = mh } -func (r *RemoveChainResponse) SetVerifyHeader(vh *session_grpc.ResponseVerificationHeader) { +func (r *RemoveChainResponse) SetVerifyHeader(vh *session.ResponseVerificationHeader) { r.VerifyHeader = vh } -func (r *ListChainsRequest_Body) SetTarget(t *ChainTarget) { +func (r *ListChainsRequest_Body) SetTarget(t *ape.ChainTarget) { r.Target = t } @@ -80,15 +81,15 @@ func (r *ListChainsRequest) SetBody(rb *ListChainsRequest_Body) { r.Body = rb } -func (r *ListChainsRequest) SetMetaHeader(mh *session_grpc.RequestMetaHeader) { +func (r *ListChainsRequest) SetMetaHeader(mh *session.RequestMetaHeader) { r.MetaHeader = mh } -func (r *ListChainsRequest) SetVerifyHeader(vh *session_grpc.RequestVerificationHeader) { +func (r *ListChainsRequest) SetVerifyHeader(vh *session.RequestVerificationHeader) { r.VerifyHeader = vh } -func (rb *ListChainsResponse_Body) SetChains(chains []*Chain) { +func (rb *ListChainsResponse_Body) SetChains(chains []*ape.Chain) { rb.Chains = chains } @@ -96,10 +97,10 @@ func (r *ListChainsResponse) SetBody(rb *ListChainsResponse_Body) { r.Body = rb } -func (r *ListChainsResponse) SetMetaHeader(mh *session_grpc.ResponseMetaHeader) { +func (r *ListChainsResponse) SetMetaHeader(mh *session.ResponseMetaHeader) { r.MetaHeader = mh } -func (r *ListChainsResponse) SetVerifyHeader(vh *session_grpc.ResponseVerificationHeader) { +func (r *ListChainsResponse) SetVerifyHeader(vh *session.ResponseVerificationHeader) { r.VerifyHeader = vh } diff --git a/apemanager/grpc/service.pb.go b/apemanager/grpc/service.pb.go index 157da44ac165633bff370a856b1da296de6c6b88..7757aadb78cf3e1abc74d316c9c67df5db6cbcce 100644 GIT binary patch delta 2243 zcmZuzYfO_@7!F;jZLPL+6kH3n6-6lpd!a?t360my!7w@jFSK7vX@OG8MM01P3Mv;T z@Tfl)75ZbpcEdDFjN8=x-$WNTvn87@Sz@wGr^&W#Guif@L&3W3Pjk+Bd*0jgywCa0 z{v^8kqiFnEign_eO(sPAYXfZ&--^pus){6RWi7{JuJt|`Fv>XoT@YTZ>tWaj@>BhQLyFZeVI`8$Pn(4h@9)-ZeA<5 z^W+6HSr67aP!ZI#+^k+$huk8YAAKV^xD+nM`^}PNa+#&e>0lR%i`cJ~YPNLQy!h1p zikcZMUUp#T$5sawosXG_8kVS9!OX=LW_CId^AzKbTbF9HvADl`T)5#;;&EURDg`Ng z!z*w^FyeK(I@`+=f6}9&3eDWx;{yt;8rhC-YP8hs9J-Q&pQ9YG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hGHjVfP6I?hz;A5PEX*TLB&5?&)UsEm*X% u@7s%Q?8{xU({ISRG{VI@AIW82zo(_U(bMJjx*HuXhc_)f^vk>Zq<;dUJSji` diff --git a/apemanager/marshal.go b/apemanager/marshal.go index 22e092e..7217709 100644 --- a/apemanager/marshal.go +++ b/apemanager/marshal.go @@ -1,19 +1,12 @@ package apemanager import ( - "fmt" - apemanager "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager/grpc" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto" ) const ( - chainTargetTargetTypeField = 1 - chainTargetNameField = 2 - - chainRawField = 1 - addChainReqBodyTargetField = 1 addChainReqBodyChainField = 2 @@ -31,82 +24,6 @@ const ( listChainsRespBodyChainsField = 1 ) -func (t *ChainTarget) StableSize() (size int) { - if t == nil { - return 0 - } - - size += proto.EnumSize(chainTargetTargetTypeField, int32(t.targeType)) - size += proto.StringSize(chainTargetNameField, t.name) - - return size -} - -func (t *ChainTarget) StableMarshal(buf []byte) []byte { - if t == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, t.StableSize()) - } - - var offset int - - offset += proto.EnumMarshal(chainTargetTargetTypeField, buf[offset:], int32(t.targeType)) - proto.StringMarshal(chainTargetNameField, buf[offset:], t.name) - - return buf -} - -func (t *ChainTarget) Unmarshal(data []byte) error { - return message.Unmarshal(t, data, new(apemanager.ChainTarget)) -} - -func (c *Chain) StableSize() (size int) { - if c == nil { - return 0 - } - - switch v := c.GetKind().(type) { - case *ChainRaw: - if v != nil { - size += proto.BytesSize(chainRawField, v.GetRaw()) - } - default: - panic(fmt.Sprintf("unsupported chain kind: %T", v)) - } - - return size -} - -func (c *Chain) StableMarshal(buf []byte) []byte { - if c == nil { - return []byte{} - } - - if buf == nil { - buf = make([]byte, c.StableSize()) - } - - var offset int - - switch v := c.GetKind().(type) { - case *ChainRaw: - if v != nil { - proto.BytesMarshal(chainRawField, buf[offset:], v.GetRaw()) - } - default: - panic(fmt.Sprintf("unsupported chain kind: %T", v)) - } - - return buf -} - -func (c *Chain) Unmarshal(data []byte) error { - return message.Unmarshal(c, data, new(apemanager.Chain)) -} - func (rb *AddChainRequestBody) StableSize() (size int) { if rb == nil { return 0 diff --git a/apemanager/message_test.go b/apemanager/message_test.go index 2d623d5..fc4d905 100644 --- a/apemanager/message_test.go +++ b/apemanager/message_test.go @@ -10,7 +10,6 @@ import ( func TestMessageConvert(t *testing.T) { messagetest.TestRPCMessage(t, - func(empty bool) message.Message { return apemanagertest.GenerateChainTarget(empty) }, func(empty bool) message.Message { return apemanagertest.GenerateAddChainRequestBody(empty) }, func(empty bool) message.Message { return apemanagertest.GenerateAddChainRequest(empty) }, func(empty bool) message.Message { return apemanagertest.GenerateAddChainResponseBody(empty) }, diff --git a/apemanager/test/generate.go b/apemanager/test/generate.go index 00dd236..192f7ad 100644 --- a/apemanager/test/generate.go +++ b/apemanager/test/generate.go @@ -1,6 +1,7 @@ package apemanagertest import ( + apetest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape/test" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager" sessiontest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/test" ) @@ -13,78 +14,12 @@ func generateChainID(empty bool) []byte { return []byte("616c6c6f774f626a476574436e72") } -func generateRawChains(empty bool, n int) []*apemanager.Chain { - if empty { - return []*apemanager.Chain{} - } - - res := make([]*apemanager.Chain, n) - for i := range res { - res[i] = generateRawChain(empty) - } - return res -} - -func generateRawChain(empty bool) *apemanager.Chain { - chRaw := new(apemanager.ChainRaw) - - if empty { - chRaw.SetRaw([]byte("{}")) - } else { - chRaw.SetRaw([]byte(`{ - "ID": "", - "Rules": [ - { - "Status": "Allow", - "Actions": { - "Inverted": false, - "Names": [ - "GetObject" - ] - }, - "Resources": { - "Inverted": false, - "Names": [ - "native:object/*" - ] - }, - "Any": false, - "Condition": [ - { - "Op": "StringEquals", - "Object": "Resource", - "Key": "Department", - "Value": "HR" - } - ] - } - ], - "MatchType": "DenyPriority" - }`)) - } - - ch := new(apemanager.Chain) - ch.SetKind(chRaw) - return ch -} - -func GenerateChainTarget(empty bool) *apemanager.ChainTarget { - m := new(apemanager.ChainTarget) - - if !empty { - m.SetTargetType(apemanager.TargetTypeContainer) - m.SetName("BzQw5HH3feoxFDD5tCT87Y1726qzgLfxEE7wgtoRzB3R") - } - - return m -} - func GenerateAddChainRequestBody(empty bool) *apemanager.AddChainRequestBody { m := new(apemanager.AddChainRequestBody) if !empty { - m.SetTarget(GenerateChainTarget(empty)) - m.SetChain(generateRawChain(empty)) + m.SetTarget(apetest.GenerateChainTarget(empty)) + m.SetChain(apetest.GenerateRawChain(empty)) } return m @@ -129,7 +64,7 @@ func GenerateRemoveChainRequestBody(empty bool) *apemanager.RemoveChainRequestBo if !empty { m.SetChainID(generateChainID(empty)) - m.SetTarget(GenerateChainTarget(empty)) + m.SetTarget(apetest.GenerateChainTarget(empty)) } return m @@ -167,7 +102,7 @@ func GenerateListChainsRequestBody(empty bool) *apemanager.ListChainsRequestBody m := new(apemanager.ListChainsRequestBody) if !empty { - m.SetTarget(GenerateChainTarget(empty)) + m.SetTarget(apetest.GenerateChainTarget(empty)) } return m @@ -189,7 +124,7 @@ func GenerateListChainsResponseBody(empty bool) *apemanager.ListChainsResponseBo m := new(apemanager.ListChainsResponseBody) if !empty { - m.SetChains(generateRawChains(empty, 10)) + m.SetChains(apetest.GenerateRawChains(empty, 10)) } return m diff --git a/apemanager/types.go b/apemanager/types.go index 1fcca29..6896bf1 100644 --- a/apemanager/types.go +++ b/apemanager/types.go @@ -1,49 +1,10 @@ package apemanager import ( + "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/ape" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" ) -type TargetType uint32 - -const ( - TargetTypeUndefined TargetType = iota - TargetTypeNamespace - TargetTypeContainer - TargetTypeUser - TargetTypeGroup -) - -type ChainTarget struct { - targeType TargetType - - name string -} - -func (ct *ChainTarget) SetTargetType(targeType TargetType) { - ct.targeType = targeType -} - -func (ct *ChainTarget) SetName(name string) { - ct.name = name -} - -func (ct *ChainTarget) GetTargetType() TargetType { - if ct != nil { - return ct.targeType - } - - return 0 -} - -func (ct *ChainTarget) GetName() string { - if ct != nil { - return ct.name - } - - return "" -} - type AddChainRequest struct { body *AddChainRequestBody @@ -58,55 +19,25 @@ func (r *AddChainRequest) GetBody() *AddChainRequestBody { return r.body } -type chainKind interface { - isChainKind() -} - -type Chain struct { - kind chainKind -} - -func (c *Chain) SetKind(kind chainKind) { - c.kind = kind -} - -func (c *Chain) GetKind() chainKind { - return c.kind -} - -type ChainRaw struct { - Raw []byte -} - -func (*ChainRaw) isChainKind() {} - -func (c *ChainRaw) SetRaw(raw []byte) { - c.Raw = raw -} - -func (c *ChainRaw) GetRaw() []byte { - return c.Raw -} - type AddChainRequestBody struct { - target *ChainTarget + target *ape.ChainTarget - chain *Chain + chain *ape.Chain } -func (rb *AddChainRequestBody) SetTarget(target *ChainTarget) { +func (rb *AddChainRequestBody) SetTarget(target *ape.ChainTarget) { rb.target = target } -func (rb *AddChainRequestBody) GetTarget() *ChainTarget { +func (rb *AddChainRequestBody) GetTarget() *ape.ChainTarget { return rb.target } -func (rb *AddChainRequestBody) SetChain(chain *Chain) { +func (rb *AddChainRequestBody) SetChain(chain *ape.Chain) { rb.chain = chain } -func (rb *AddChainRequestBody) GetChain() *Chain { +func (rb *AddChainRequestBody) GetChain() *ape.Chain { return rb.chain } @@ -151,16 +82,16 @@ func (r *RemoveChainRequest) GetBody() *RemoveChainRequestBody { } type RemoveChainRequestBody struct { - target *ChainTarget + target *ape.ChainTarget chainID []byte } -func (rb *RemoveChainRequestBody) SetTarget(target *ChainTarget) { +func (rb *RemoveChainRequestBody) SetTarget(target *ape.ChainTarget) { rb.target = target } -func (rb *RemoveChainRequestBody) GetTarget() *ChainTarget { +func (rb *RemoveChainRequestBody) GetTarget() *ape.ChainTarget { return rb.target } @@ -204,14 +135,14 @@ func (r *ListChainsRequest) GetBody() *ListChainsRequestBody { } type ListChainsRequestBody struct { - target *ChainTarget + target *ape.ChainTarget } -func (rb *ListChainsRequestBody) SetTarget(target *ChainTarget) { +func (rb *ListChainsRequestBody) SetTarget(target *ape.ChainTarget) { rb.target = target } -func (rb *ListChainsRequestBody) GetTarget() *ChainTarget { +func (rb *ListChainsRequestBody) GetTarget() *ape.ChainTarget { return rb.target } @@ -230,15 +161,15 @@ func (r *ListChainsResponse) GetBody() *ListChainsResponseBody { } type ListChainsResponseBody struct { - chains []*Chain + chains []*ape.Chain session.RequestHeaders } -func (r *ListChainsResponseBody) SetChains(chains []*Chain) { +func (r *ListChainsResponseBody) SetChains(chains []*ape.Chain) { r.chains = chains } -func (r *ListChainsResponseBody) GetChains() []*Chain { +func (r *ListChainsResponseBody) GetChains() []*ape.Chain { return r.chains }