Compare commits

...

1 commit

Author SHA1 Message Date
97e260b3fa [#74] apemanager: Generate protobufs for apemanager service
All checks were successful
Tests and linters / Tests (1.19) (pull_request) Successful in 7m50s
Tests and linters / Tests (1.20) (pull_request) Successful in 7m50s
Tests and linters / Lint (pull_request) Successful in 8m34s
DCO action / DCO (pull_request) Successful in 8m54s
Tests and linters / Tests with -race (pull_request) Successful in 9m18s
* Generate protobufs.
* Make marshallers, unmarshallers, json-encoders etc.
* Create message encoding/decoding unit-tests.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-05-02 10:42:30 +03:00
17 changed files with 1587 additions and 0 deletions

481
apemanager/convert.go Normal file
View file

@ -0,0 +1,481 @@
package apemanager
import (
"fmt"
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))
}
return reqBodygrpc
}
func (reqBody *AddChainRequestBody) FromGRPCMessage(m grpc.Message) error {
reqBodygrpc, ok := m.(*apemanager.AddChainRequest_Body)
if !ok {
return message.NewUnexpectedMessageType(m, reqBodygrpc)
}
if targetgrpc := reqBodygrpc.GetTarget(); targetgrpc != nil {
reqBody.target = new(ChainTarget)
if err := reqBody.target.FromGRPCMessage(targetgrpc); err != nil {
return err
}
}
if chaingrpc := reqBodygrpc.GetChain(); chaingrpc != nil {
reqBody.chain = new(Chain)
if err := reqBody.GetChain().FromGRPCMessage(chaingrpc); err != nil {
return err
}
}
return nil
}
func (req *AddChainRequest) ToGRPCMessage() grpc.Message {
var reqgrpc *apemanager.AddChainRequest
if req != nil {
reqgrpc = new(apemanager.AddChainRequest)
reqgrpc.SetBody(req.GetBody().ToGRPCMessage().(*apemanager.AddChainRequest_Body))
req.RequestHeaders.ToMessage(reqgrpc)
}
return reqgrpc
}
func (req *AddChainRequest) FromGRPCMessage(m grpc.Message) error {
reqgrpc, ok := m.(*apemanager.AddChainRequest)
if !ok {
return message.NewUnexpectedMessageType(m, reqgrpc)
}
if reqBodygrpc := reqgrpc.GetBody(); reqBodygrpc != nil {
req.body = new(AddChainRequestBody)
if err := req.body.FromGRPCMessage(reqBodygrpc); err != nil {
return err
}
}
return req.RequestHeaders.FromMessage(reqgrpc)
}
func (respBody *AddChainResponseBody) ToGRPCMessage() grpc.Message {
var respBodygrpc *apemanager.AddChainResponse_Body
if respBody != nil {
respBodygrpc = new(apemanager.AddChainResponse_Body)
respBodygrpc.SetChainID(respBody.GetChainID())
}
return respBodygrpc
}
func (respBody *AddChainResponseBody) FromGRPCMessage(m grpc.Message) error {
respBodygrpc, ok := m.(*apemanager.AddChainResponse_Body)
if !ok {
return message.NewUnexpectedMessageType(m, respBodygrpc)
}
respBody.SetChainID(respBodygrpc.GetChainId())
return nil
}
func (resp *AddChainResponse) ToGRPCMessage() grpc.Message {
var respgrpc *apemanager.AddChainResponse
if resp != nil {
respgrpc = new(apemanager.AddChainResponse)
respgrpc.SetBody(resp.body.ToGRPCMessage().(*apemanager.AddChainResponse_Body))
resp.ResponseHeaders.ToMessage(respgrpc)
}
return respgrpc
}
func (resp *AddChainResponse) FromGRPCMessage(m grpc.Message) error {
respgrpc, ok := m.(*apemanager.AddChainResponse)
if !ok {
return message.NewUnexpectedMessageType(m, respgrpc)
}
if respBodygrpc := respgrpc.GetBody(); respBodygrpc != nil {
resp.body = new(AddChainResponseBody)
if err := resp.body.FromGRPCMessage(respBodygrpc); err != nil {
return err
}
}
return resp.ResponseHeaders.FromMessage(respgrpc)
}
func (reqBody *RemoveChainRequestBody) ToGRPCMessage() grpc.Message {
var reqBodygrpc *apemanager.RemoveChainRequest_Body
if reqBody != nil {
reqBodygrpc = new(apemanager.RemoveChainRequest_Body)
reqBodygrpc.SetTarget(reqBody.target.ToGRPCMessage().(*apemanager.ChainTarget))
reqBodygrpc.SetChainID(reqBody.GetChainID())
}
return reqBodygrpc
}
func (reqBody *RemoveChainRequestBody) FromGRPCMessage(m grpc.Message) error {
reqBodygrpc, ok := m.(*apemanager.RemoveChainRequest_Body)
if !ok {
return message.NewUnexpectedMessageType(m, reqBodygrpc)
}
if targetgrpc := reqBodygrpc.GetTarget(); targetgrpc != nil {
reqBody.target = new(ChainTarget)
if err := reqBody.target.FromGRPCMessage(targetgrpc); err != nil {
return err
}
}
reqBody.SetChainID(reqBodygrpc.GetChainId())
return nil
}
func (req *RemoveChainRequest) ToGRPCMessage() grpc.Message {
var reqgrpc *apemanager.RemoveChainRequest
if req != nil {
reqgrpc = new(apemanager.RemoveChainRequest)
reqgrpc.SetBody(req.body.ToGRPCMessage().(*apemanager.RemoveChainRequest_Body))
req.RequestHeaders.ToMessage(reqgrpc)
}
return reqgrpc
}
func (req *RemoveChainRequest) FromGRPCMessage(m grpc.Message) error {
reqgrpc, ok := m.(*apemanager.RemoveChainRequest)
if !ok {
return message.NewUnexpectedMessageType(m, reqgrpc)
}
if reqBodygrpc := reqgrpc.GetBody(); reqBodygrpc != nil {
req.body = new(RemoveChainRequestBody)
if err := req.body.FromGRPCMessage(reqBodygrpc); err != nil {
return err
}
}
return req.RequestHeaders.FromMessage(reqgrpc)
}
func (respBody *RemoveChainResponseBody) ToGRPCMessage() grpc.Message {
var respBodygrpc *apemanager.RemoveChainResponse_Body
if respBody != nil {
respBodygrpc = new(apemanager.RemoveChainResponse_Body)
}
return respBodygrpc
}
func (respBody *RemoveChainResponseBody) FromGRPCMessage(m grpc.Message) error {
respBodygrpc, ok := m.(*apemanager.RemoveChainResponse_Body)
if !ok {
return message.NewUnexpectedMessageType(m, respBodygrpc)
}
return nil
}
func (resp *RemoveChainResponse) ToGRPCMessage() grpc.Message {
var respgrpc *apemanager.RemoveChainResponse
if resp != nil {
respgrpc = new(apemanager.RemoveChainResponse)
respgrpc.SetBody(resp.body.ToGRPCMessage().(*apemanager.RemoveChainResponse_Body))
resp.ResponseHeaders.ToMessage(respgrpc)
}
return respgrpc
}
func (resp *RemoveChainResponse) FromGRPCMessage(m grpc.Message) error {
respgrpc, ok := m.(*apemanager.RemoveChainResponse)
if !ok {
return message.NewUnexpectedMessageType(m, respgrpc)
}
if respBodygrpc := respgrpc.GetBody(); respBodygrpc != nil {
resp.body = new(RemoveChainResponseBody)
if err := resp.body.FromGRPCMessage(respBodygrpc); err != nil {
return err
}
}
return resp.ResponseHeaders.FromMessage(respgrpc)
}
func (reqBody *ListChainsRequestBody) ToGRPCMessage() grpc.Message {
var reqBodygrpc *apemanager.ListChainsRequest_Body
if reqBody != nil {
reqBodygrpc = new(apemanager.ListChainsRequest_Body)
reqBodygrpc.SetTarget(reqBody.target.ToGRPCMessage().(*apemanager.ChainTarget))
}
return reqBodygrpc
}
func (reqBody *ListChainsRequestBody) FromGRPCMessage(m grpc.Message) error {
reqBodygrpc, ok := m.(*apemanager.ListChainsRequest_Body)
if !ok {
return message.NewUnexpectedMessageType(m, reqBodygrpc)
}
if targetgrpc := reqBodygrpc.GetTarget(); targetgrpc != nil {
reqBody.target = new(ChainTarget)
if err := reqBody.target.FromGRPCMessage(targetgrpc); err != nil {
return err
}
}
return nil
}
func (req *ListChainsRequest) ToGRPCMessage() grpc.Message {
var reqgrpc *apemanager.ListChainsRequest
if req != nil {
reqgrpc = new(apemanager.ListChainsRequest)
reqgrpc.SetBody(req.body.ToGRPCMessage().(*apemanager.ListChainsRequest_Body))
req.RequestHeaders.ToMessage(reqgrpc)
}
return reqgrpc
}
func (req *ListChainsRequest) FromGRPCMessage(m grpc.Message) error {
reqgrpc, ok := m.(*apemanager.ListChainsRequest)
if !ok {
return message.NewUnexpectedMessageType(m, reqgrpc)
}
if reqBodygrpc := reqgrpc.GetBody(); reqBodygrpc != nil {
req.body = new(ListChainsRequestBody)
if err := req.body.FromGRPCMessage(reqBodygrpc); err != nil {
return err
}
}
return req.RequestHeaders.FromMessage(reqgrpc)
}
func (respBody *ListChainsResponseBody) ToGRPCMessage() grpc.Message {
var respBodygrpc *apemanager.ListChainsResponse_Body
if respBody != nil {
respBodygrpc = new(apemanager.ListChainsResponse_Body)
chainsgrpc := make([]*apemanager.Chain, 0, len(respBody.GetChains()))
for _, chain := range respBody.GetChains() {
chainsgrpc = append(chainsgrpc, chain.ToGRPCMessage().(*apemanager.Chain))
}
respBodygrpc.SetChains(chainsgrpc)
}
return respBodygrpc
}
func (respBody *ListChainsResponseBody) FromGRPCMessage(m grpc.Message) error {
respBodygrpc, ok := m.(*apemanager.ListChainsResponse_Body)
if !ok {
return message.NewUnexpectedMessageType(m, respBodygrpc)
}
chains := make([]*Chain, 0, len(respBodygrpc.GetChains()))
for _, chaingrpc := range respBodygrpc.GetChains() {
chain := new(Chain)
if err := chain.FromGRPCMessage(chaingrpc); err != nil {
return err
}
chains = append(chains, chain)
}
respBody.SetChains(chains)
return nil
}
func (resp *ListChainsResponse) ToGRPCMessage() grpc.Message {
var respgrpc *apemanager.ListChainsResponse
if resp != nil {
respgrpc = new(apemanager.ListChainsResponse)
respgrpc.SetBody(resp.body.ToGRPCMessage().(*apemanager.ListChainsResponse_Body))
resp.ResponseHeaders.ToMessage(respgrpc)
}
return respgrpc
}
func (resp *ListChainsResponse) FromGRPCMessage(m grpc.Message) error {
respgrpc, ok := m.(*apemanager.ListChainsResponse)
if !ok {
return message.NewUnexpectedMessageType(m, respgrpc)
}
if respBodygrpc := respgrpc.GetBody(); respBodygrpc != nil {
resp.body = new(ListChainsResponseBody)
if err := resp.body.FromGRPCMessage(respBodygrpc); err != nil {
return err
}
}
return resp.ResponseHeaders.FromMessage(respgrpc)
}

105
apemanager/grpc/service.go Normal file
View file

@ -0,0 +1,105 @@
package apemanager
import (
session_grpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/grpc"
)
func (rb *AddChainRequest_Body) SetTarget(t *ChainTarget) {
rb.Target = t
}
func (rb *AddChainRequest_Body) SetChain(chain *Chain) {
rb.Chain = chain
}
func (r *AddChainRequest) SetBody(rb *AddChainRequest_Body) {
r.Body = rb
}
func (r *AddChainRequest) SetMetaHeader(mh *session_grpc.RequestMetaHeader) {
r.MetaHeader = mh
}
func (r *AddChainRequest) SetVerifyHeader(vh *session_grpc.RequestVerificationHeader) {
r.VerifyHeader = vh
}
func (rb *AddChainResponse_Body) SetChainID(chainID []byte) {
rb.ChainId = chainID
}
func (r *AddChainResponse) SetBody(rb *AddChainResponse_Body) {
r.Body = rb
}
func (r *AddChainResponse) SetMetaHeader(mh *session_grpc.ResponseMetaHeader) {
r.MetaHeader = mh
}
func (r *AddChainResponse) SetVerifyHeader(vh *session_grpc.ResponseVerificationHeader) {
r.VerifyHeader = vh
}
func (rb *RemoveChainRequest_Body) SetTarget(t *ChainTarget) {
rb.Target = t
}
func (rb *RemoveChainRequest_Body) SetChainID(chainID []byte) {
rb.ChainId = chainID
}
func (r *RemoveChainRequest) SetBody(rb *RemoveChainRequest_Body) {
r.Body = rb
}
func (r *RemoveChainRequest) SetMetaHeader(mh *session_grpc.RequestMetaHeader) {
r.MetaHeader = mh
}
func (r *RemoveChainRequest) SetVerifyHeader(vh *session_grpc.RequestVerificationHeader) {
r.VerifyHeader = vh
}
func (r *RemoveChainResponse) SetBody(rb *RemoveChainResponse_Body) {
r.Body = rb
}
func (r *RemoveChainResponse) SetMetaHeader(mh *session_grpc.ResponseMetaHeader) {
r.MetaHeader = mh
}
func (r *RemoveChainResponse) SetVerifyHeader(vh *session_grpc.ResponseVerificationHeader) {
r.VerifyHeader = vh
}
func (r *ListChainsRequest_Body) SetTarget(t *ChainTarget) {
r.Target = t
}
func (r *ListChainsRequest) SetBody(rb *ListChainsRequest_Body) {
r.Body = rb
}
func (r *ListChainsRequest) SetMetaHeader(mh *session_grpc.RequestMetaHeader) {
r.MetaHeader = mh
}
func (r *ListChainsRequest) SetVerifyHeader(vh *session_grpc.RequestVerificationHeader) {
r.VerifyHeader = vh
}
func (rb *ListChainsResponse_Body) SetChains(chains []*Chain) {
rb.Chains = chains
}
func (r *ListChainsResponse) SetBody(rb *ListChainsResponse_Body) {
r.Body = rb
}
func (r *ListChainsResponse) SetMetaHeader(mh *session_grpc.ResponseMetaHeader) {
r.MetaHeader = mh
}
func (r *ListChainsResponse) SetVerifyHeader(vh *session_grpc.ResponseVerificationHeader) {
r.VerifyHeader = vh
}

BIN
apemanager/grpc/service.pb.go generated Normal file

Binary file not shown.

BIN
apemanager/grpc/service_grpc.pb.go generated Normal file

Binary file not shown.

21
apemanager/grpc/types.go Normal file
View file

@ -0,0 +1,21 @@
package apemanager
func (t *ChainTarget) SetType(typ TargetType) {
t.Type = typ
}
func (t *ChainTarget) SetName(name string) {
t.Name = name
}
func (c *Chain) SetKind(kind isChain_Kind) {
c.Kind = kind
}
func (cr *Chain_Raw) SetRaw(raw []byte) {
cr.Raw = raw
}
func (cr *Chain_Raw) GetRaw() []byte {
return cr.Raw
}

BIN
apemanager/grpc/types.pb.go generated Normal file

Binary file not shown.

14
apemanager/json.go Normal file
View file

@ -0,0 +1,14 @@
package apemanager
import (
apemanager_grpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager/grpc"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
)
func (t *ChainTarget) MarshalJSON() ([]byte, error) {
return message.MarshalJSON(t)
}
func (t *ChainTarget) UnmarshalJSON(data []byte) error {
return message.UnmarshalJSON(t, data, new(apemanager_grpc.ChainTarget))
}

288
apemanager/marshal.go Normal file
View file

@ -0,0 +1,288 @@
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
addChainRespBodyChainIDField = 1
removeChainReqBodyTargetField = 1
removeChainReqBodyChainField = 2
/*
Fields for RemoveResponseBody are missed since RemoveResponseBody is empty.
*/
listChainsReqBodyTargetField = 1
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
}
size += proto.NestedStructureSize(addChainReqBodyTargetField, rb.target)
size += proto.NestedStructureSize(addChainReqBodyChainField, rb.chain)
return size
}
func (rb *AddChainRequestBody) StableMarshal(buf []byte) []byte {
if rb == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, rb.StableSize())
}
var offset int
offset += proto.NestedStructureMarshal(addChainReqBodyTargetField, buf[offset:], rb.target)
proto.NestedStructureMarshal(addChainReqBodyChainField, buf[offset:], rb.chain)
return buf
}
func (rb *AddChainRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(rb, data, new(apemanager.AddChainRequest_Body))
}
func (rb *AddChainResponseBody) StableSize() (size int) {
if rb == nil {
return 0
}
size += proto.BytesSize(addChainRespBodyChainIDField, rb.chainID)
return size
}
func (rb *AddChainResponseBody) StableMarshal(buf []byte) []byte {
if rb == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, rb.StableSize())
}
var offset int
proto.BytesMarshal(addChainRespBodyChainIDField, buf[offset:], rb.chainID)
return buf
}
func (rb *AddChainResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(rb, data, new(apemanager.AddChainResponse_Body))
}
func (rb *RemoveChainRequestBody) StableSize() (size int) {
if rb == nil {
return 0
}
size += proto.NestedStructureSize(addChainReqBodyTargetField, rb.target)
size += proto.BytesSize(addChainReqBodyChainField, rb.chainID)
return size
}
func (rb *RemoveChainRequestBody) StableMarshal(buf []byte) []byte {
if rb == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, rb.StableSize())
}
var offset int
offset += proto.NestedStructureMarshal(removeChainReqBodyTargetField, buf[offset:], rb.target)
proto.BytesMarshal(removeChainReqBodyChainField, buf[offset:], rb.chainID)
return buf
}
func (rb *RemoveChainRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(rb, data, new(apemanager.RemoveChainRequest_Body))
}
func (rb *RemoveChainResponseBody) StableSize() (size int) {
if rb == nil {
return 0
}
return size
}
func (rb *RemoveChainResponseBody) StableMarshal(buf []byte) []byte {
if rb == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, rb.StableSize())
}
return buf
}
func (rb *RemoveChainResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(rb, data, new(apemanager.RemoveChainResponse_Body))
}
func (rb *ListChainsRequestBody) StableSize() (size int) {
if rb == nil {
return 0
}
size += proto.NestedStructureSize(listChainsReqBodyTargetField, rb.target)
return size
}
func (rb *ListChainsRequestBody) StableMarshal(buf []byte) []byte {
if rb == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, rb.StableSize())
}
var offset int
proto.NestedStructureMarshal(addChainReqBodyTargetField, buf[offset:], rb.target)
return buf
}
func (rb *ListChainsRequestBody) Unmarshal(data []byte) error {
return message.Unmarshal(rb, data, new(apemanager.ListChainsRequest_Body))
}
func (rb *ListChainsResponseBody) StableSize() (size int) {
if rb == nil {
return 0
}
for _, chain := range rb.GetChains() {
size += proto.NestedStructureSize(listChainsRespBodyChainsField, chain)
}
return size
}
func (rb *ListChainsResponseBody) StableMarshal(buf []byte) []byte {
if rb == nil {
return []byte{}
}
if buf == nil {
buf = make([]byte, rb.StableSize())
}
var offset int
for _, chain := range rb.GetChains() {
offset += proto.NestedStructureMarshal(listChainsRespBodyChainsField, buf[offset:], chain)
}
return buf
}
func (rb *ListChainsResponseBody) Unmarshal(data []byte) error {
return message.Unmarshal(rb, data, new(apemanager.ListChainsResponse_Body))
}

View file

@ -0,0 +1,27 @@
package apemanager_test
import (
"testing"
apemanagertest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager/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 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) },
func(empty bool) message.Message { return apemanagertest.GenerateAddChainResponse(empty) },
func(empty bool) message.Message { return apemanagertest.GenerateRemoveChainRequestBody(empty) },
func(empty bool) message.Message { return apemanagertest.GenerateRemoveChainRequest(empty) },
func(empty bool) message.Message { return apemanagertest.GenerateRemoveChainResponseBody(empty) },
func(empty bool) message.Message { return apemanagertest.GenerateRemoveChainResponse(empty) },
func(empty bool) message.Message { return apemanagertest.GenerateListChainsRequestBody(empty) },
func(empty bool) message.Message { return apemanagertest.GenerateListChainsRequest(empty) },
func(empty bool) message.Message { return apemanagertest.GenerateListChainsResponseBody(empty) },
func(empty bool) message.Message { return apemanagertest.GenerateListChainsResponse(empty) },
)
}

76
apemanager/status.go Normal file
View file

@ -0,0 +1,76 @@
package apemanager
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status"
statusgrpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/grpc"
)
// LocalizeFailStatus checks if passed global status.Code is related to ape manager failure and:
//
// then localizes the code and returns true,
// else leaves the code unchanged and returns false.
//
// Arg must be non-nil.
func LocalizeFailStatus(c *status.Code) bool {
return status.LocalizeIfInSection(c, uint32(statusgrpc.Section_SECTION_APE_MANAGER))
}
// GlobalizeFail globalizes local code of ape manager failure.
//
// Arg must be non-nil.
func GlobalizeFail(c *status.Code) {
c.GlobalizeSection(uint32(statusgrpc.Section_SECTION_APE_MANAGER))
}
const (
// StatusAPEManagerAccessDenied is a local status.Code value for
// ACCESS_DENIED ape manager failure.
StatusAPEManagerAccessDenied status.Code = iota
)
const (
// detailAccessDeniedDesc is a StatusAccessDenied detail ID for
// human-readable description.
detailAccessDeniedDesc = iota
)
// WriteAccessDeniedDesc writes human-readable description of StatusAccessDenied
// into status.Status as a detail. The status must not be nil.
//
// Existing details are expected to be ID-unique, otherwise undefined behavior.
func WriteAccessDeniedDesc(st *status.Status, desc string) {
var found bool
st.IterateDetails(func(d *status.Detail) bool {
if d.ID() == detailAccessDeniedDesc {
found = true
d.SetValue([]byte(desc))
}
return found
})
if !found {
var d status.Detail
d.SetID(detailAccessDeniedDesc)
d.SetValue([]byte(desc))
st.AppendDetails(d)
}
}
// ReadAccessDeniedDesc looks up for status detail with human-readable description
// of StatusAccessDenied. Returns empty string if detail is missing.
func ReadAccessDeniedDesc(st status.Status) (desc string) {
st.IterateDetails(func(d *status.Detail) bool {
if d.ID() == detailAccessDeniedDesc {
desc = string(d.Value())
return true
}
return false
})
return
}

30
apemanager/status_test.go Normal file
View file

@ -0,0 +1,30 @@
package apemanager_test
import (
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status"
statustest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/test"
"github.com/stretchr/testify/require"
)
func TestStatusCodes(t *testing.T) {
statustest.TestCodes(t, apemanager.LocalizeFailStatus, apemanager.GlobalizeFail,
apemanager.StatusAPEManagerAccessDenied, 5120,
)
}
func TestAccessDeniedDesc(t *testing.T) {
var st status.Status
require.Empty(t, apemanager.ReadAccessDeniedDesc(st))
const desc = "some description"
apemanager.WriteAccessDeniedDesc(&st, desc)
require.Equal(t, desc, apemanager.ReadAccessDeniedDesc(st))
apemanager.WriteAccessDeniedDesc(&st, desc+"1")
require.Equal(t, desc+"1", apemanager.ReadAccessDeniedDesc(st))
}

18
apemanager/string.go Normal file
View file

@ -0,0 +1,18 @@
package apemanager
import (
apemanager_grpc "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager/grpc"
)
func (tt TargetType) String() string {
return TargetTypeToGRPCField(tt).String()
}
func (tt *TargetType) FromString(s string) bool {
i, ok := apemanager_grpc.TargetType_value[s]
if ok {
*tt = TargetType(i)
}
return ok
}

208
apemanager/test/generate.go Normal file
View file

@ -0,0 +1,208 @@
package apemanagertest
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager"
sessiontest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/test"
)
func generateChainID(empty bool) []byte {
if empty {
return []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))
}
return m
}
func GenerateAddChainRequest(empty bool) *apemanager.AddChainRequest {
m := new(apemanager.AddChainRequest)
if !empty {
m.SetBody(GenerateAddChainRequestBody(empty))
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
}
return m
}
func GenerateAddChainResponseBody(empty bool) *apemanager.AddChainResponseBody {
m := new(apemanager.AddChainResponseBody)
if !empty {
m.SetChainID(generateChainID(empty))
}
return m
}
func GenerateAddChainResponse(empty bool) *apemanager.AddChainResponse {
m := new(apemanager.AddChainResponse)
if !empty {
m.SetBody(GenerateAddChainResponseBody(empty))
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
}
return m
}
func GenerateRemoveChainRequestBody(empty bool) *apemanager.RemoveChainRequestBody {
m := new(apemanager.RemoveChainRequestBody)
if !empty {
m.SetChainID(generateChainID(empty))
m.SetTarget(GenerateChainTarget(empty))
}
return m
}
func GenerateRemoveChainRequest(empty bool) *apemanager.RemoveChainRequest {
m := new(apemanager.RemoveChainRequest)
if !empty {
m.SetBody(GenerateRemoveChainRequestBody(empty))
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
}
return m
}
func GenerateRemoveChainResponseBody(_ bool) *apemanager.RemoveChainResponseBody {
return new(apemanager.RemoveChainResponseBody)
}
func GenerateRemoveChainResponse(empty bool) *apemanager.RemoveChainResponse {
m := new(apemanager.RemoveChainResponse)
if !empty {
m.SetBody(GenerateRemoveChainResponseBody(empty))
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
}
return m
}
func GenerateListChainsRequestBody(empty bool) *apemanager.ListChainsRequestBody {
m := new(apemanager.ListChainsRequestBody)
if !empty {
m.SetTarget(GenerateChainTarget(empty))
}
return m
}
func GenerateListChainsRequest(empty bool) *apemanager.ListChainsRequest {
m := new(apemanager.ListChainsRequest)
if !empty {
m.SetBody(GenerateListChainsRequestBody(empty))
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
}
return m
}
func GenerateListChainsResponseBody(empty bool) *apemanager.ListChainsResponseBody {
m := new(apemanager.ListChainsResponseBody)
if !empty {
m.SetChains(generateRawChains(empty, 10))
}
return m
}
func GenerateListChainsResponse(empty bool) *apemanager.ListChainsResponse {
m := new(apemanager.ListChainsResponse)
if !empty {
m.SetBody(GenerateListChainsResponseBody(empty))
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
}
return m
}

244
apemanager/types.go Normal file
View file

@ -0,0 +1,244 @@
package apemanager
import (
"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
session.RequestHeaders
}
func (r *AddChainRequest) SetBody(body *AddChainRequestBody) {
r.body = body
}
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
chain *Chain
}
func (rb *AddChainRequestBody) SetTarget(target *ChainTarget) {
rb.target = target
}
func (rb *AddChainRequestBody) GetTarget() *ChainTarget {
return rb.target
}
func (rb *AddChainRequestBody) SetChain(chain *Chain) {
rb.chain = chain
}
func (rb *AddChainRequestBody) GetChain() *Chain {
return rb.chain
}
type AddChainResponse struct {
body *AddChainResponseBody
session.ResponseHeaders
}
func (r *AddChainResponse) SetBody(body *AddChainResponseBody) {
r.body = body
}
func (r *AddChainResponse) GetBody() *AddChainResponseBody {
return r.body
}
type AddChainResponseBody struct {
chainID []byte
}
func (rb *AddChainResponseBody) SetChainID(chainID []byte) {
rb.chainID = chainID
}
func (rb *AddChainResponseBody) GetChainID() []byte {
return rb.chainID
}
type RemoveChainRequest struct {
body *RemoveChainRequestBody
session.RequestHeaders
}
func (r *RemoveChainRequest) SetBody(body *RemoveChainRequestBody) {
r.body = body
}
func (r *RemoveChainRequest) GetBody() *RemoveChainRequestBody {
return r.body
}
type RemoveChainRequestBody struct {
target *ChainTarget
chainID []byte
}
func (rb *RemoveChainRequestBody) SetTarget(target *ChainTarget) {
rb.target = target
}
func (rb *RemoveChainRequestBody) GetTarget() *ChainTarget {
return rb.target
}
func (rb *RemoveChainRequestBody) SetChainID(chainID []byte) {
rb.chainID = chainID
}
func (rb *RemoveChainRequestBody) GetChainID() []byte {
return rb.chainID
}
type RemoveChainResponse struct {
body *RemoveChainResponseBody
session.ResponseHeaders
}
type RemoveChainResponseBody struct {
}
func (r *RemoveChainResponse) SetBody(body *RemoveChainResponseBody) {
r.body = body
}
func (r *RemoveChainResponse) GetBody() *RemoveChainResponseBody {
return r.body
}
type ListChainsRequest struct {
body *ListChainsRequestBody
session.RequestHeaders
}
func (r *ListChainsRequest) SetBody(body *ListChainsRequestBody) {
r.body = body
}
func (r *ListChainsRequest) GetBody() *ListChainsRequestBody {
return r.body
}
type ListChainsRequestBody struct {
target *ChainTarget
}
func (rb *ListChainsRequestBody) SetTarget(target *ChainTarget) {
rb.target = target
}
func (rb *ListChainsRequestBody) GetTarget() *ChainTarget {
return rb.target
}
type ListChainsResponse struct {
body *ListChainsResponseBody
session.ResponseHeaders
}
func (r *ListChainsResponse) SetBody(body *ListChainsResponseBody) {
r.body = body
}
func (r *ListChainsResponse) GetBody() *ListChainsResponseBody {
return r.body
}
type ListChainsResponseBody struct {
chains []*Chain
session.RequestHeaders
}
func (r *ListChainsResponseBody) SetChains(chains []*Chain) {
r.chains = chains
}
func (r *ListChainsResponseBody) GetChains() []*Chain {
return r.chains
}

60
rpc/apemanager.go Normal file
View file

@ -0,0 +1,60 @@
package rpc
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common"
)
const serviceAPEManager = serviceNamePrefix + "apemanager.APEManagerService"
const (
rpcAPEManagerAddChain = "AddChain"
rpcAPEManagerRemoveChain = "RemoveChain"
rpcAPEManagerListChains = "ListChains"
)
func AddChain(
cli *client.Client,
req *apemanager.AddChainRequest,
opts ...client.CallOption,
) (*apemanager.AddChainResponse, error) {
resp := new(apemanager.AddChainResponse)
err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceAPEManager, rpcAPEManagerAddChain), req, resp, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
func RemoveChain(
cli *client.Client,
req *apemanager.RemoveChainRequest,
opts ...client.CallOption,
) (*apemanager.RemoveChainResponse, error) {
resp := new(apemanager.RemoveChainResponse)
err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceAPEManager, rpcAPEManagerRemoveChain), req, resp, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
func ListChains(
cli *client.Client,
req *apemanager.ListChainsRequest,
opts ...client.CallOption,
) (*apemanager.ListChainsResponse, error) {
resp := new(apemanager.ListChainsResponse)
err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceAPEManager, rpcAPEManagerListChains), req, resp, opts...)
if err != nil {
return nil, err
}
return resp, nil
}

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
@ -105,5 +106,19 @@ func serviceMessageBody(req any) stableMarshaler {
return v.GetBody() return v.GetBody()
case *netmap.SnapshotResponse: case *netmap.SnapshotResponse:
return v.GetBody() return v.GetBody()
/* APEManager */
case *apemanager.AddChainRequest:
return v.GetBody()
case *apemanager.AddChainResponse:
return v.GetBody()
case *apemanager.RemoveChainRequest:
return v.GetBody()
case *apemanager.RemoveChainResponse:
return v.GetBody()
case *apemanager.ListChainsRequest:
return v.GetBody()
case *apemanager.ListChainsResponse:
return v.GetBody()
} }
} }

BIN
status/grpc/types.pb.go generated

Binary file not shown.