[#283] control: Changed type of chainID to bytes

Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
Denis Kirillov 2023-12-20 16:23:29 +03:00
parent 5698d5844e
commit 6509639540
5 changed files with 25 additions and 25 deletions

View file

@ -94,7 +94,7 @@ func (c *Client) RemovePolicies(ctx context.Context, policies []PolicyInfo) erro
for i := range policies { for i := range policies {
chainInfos[i] = &control.RemovePoliciesRequest_ChainInfo{ chainInfos[i] = &control.RemovePoliciesRequest_ChainInfo{
Namespace: policies[i].Namespace, Namespace: policies[i].Namespace,
ChainID: string(policies[i].ChainID), ChainID: []byte(policies[i].ChainID),
} }
} }
@ -116,7 +116,7 @@ func (c *Client) GetPolicy(ctx context.Context, namespace string, chainID chain.
req := &control.GetPolicyRequest{ req := &control.GetPolicyRequest{
Body: &control.GetPolicyRequest_Body{ Body: &control.GetPolicyRequest_Body{
Namespace: namespace, Namespace: namespace,
ChainID: string(chainID), ChainID: []byte(chainID),
}, },
} }

View file

@ -185,7 +185,7 @@ func (s *Server) removePolicy(info *control.RemovePoliciesRequest_ChainInfo) err
// If request is unsigned or signed by disallowed key, permission error returns. // If request is unsigned or signed by disallowed key, permission error returns.
func (s *Server) GetPolicy(_ context.Context, req *control.GetPolicyRequest) (*control.GetPolicyResponse, error) { func (s *Server) GetPolicy(_ context.Context, req *control.GetPolicyRequest) (*control.GetPolicyResponse, error) {
s.log.Info(logs.ControlAPIGetPolicy, zap.String("namespace", req.GetBody().GetNamespace()), s.log.Info(logs.ControlAPIGetPolicy, zap.String("namespace", req.GetBody().GetNamespace()),
zap.String("chainId", req.GetBody().GetChainID()), zap.String("key", hex.EncodeToString(req.Signature.Key))) zap.Binary("chainId", req.GetBody().GetChainID()), zap.String("key", hex.EncodeToString(req.Signature.Key)))
// verify request // verify request
if err := s.isValidRequest(req); err != nil { if err := s.isValidRequest(req); err != nil {
@ -219,9 +219,9 @@ func (s *Server) ListPolicies(_ context.Context, req *control.ListPoliciesReques
return nil, status.Error(codes.InvalidArgument, err.Error()) return nil, status.Error(codes.InvalidArgument, err.Error())
} }
res := make([]string, len(chains)) res := make([][]byte, len(chains))
for i := range chains { for i := range chains {
res[i] = string(chains[i].ID) res[i] = []byte(chains[i].ID)
} }
return &control.ListPoliciesResponse{Body: &control.ListPoliciesResponse_Body{ChainIDs: res}}, nil return &control.ListPoliciesResponse{Body: &control.ListPoliciesResponse_Body{ChainIDs: res}}, nil

View file

@ -939,7 +939,7 @@ type RemovePoliciesRequest_ChainInfo struct {
// Namespace. // Namespace.
Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"` Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"`
// Chain id to remove. // Chain id to remove.
ChainID string `protobuf:"bytes,2,opt,name=chainID,proto3" json:"chainID,omitempty"` ChainID []byte `protobuf:"bytes,2,opt,name=chainID,proto3" json:"chainID,omitempty"`
} }
func (x *RemovePoliciesRequest_ChainInfo) Reset() { func (x *RemovePoliciesRequest_ChainInfo) Reset() {
@ -981,11 +981,11 @@ func (x *RemovePoliciesRequest_ChainInfo) GetNamespace() string {
return "" return ""
} }
func (x *RemovePoliciesRequest_ChainInfo) GetChainID() string { func (x *RemovePoliciesRequest_ChainInfo) GetChainID() []byte {
if x != nil { if x != nil {
return x.ChainID return x.ChainID
} }
return "" return nil
} }
type RemovePoliciesRequest_Body struct { type RemovePoliciesRequest_Body struct {
@ -1081,7 +1081,7 @@ type GetPolicyRequest_Body struct {
// Namespace. // Namespace.
Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"` Namespace string `protobuf:"bytes,1,opt,name=namespace,proto3" json:"namespace,omitempty"`
// Chain id to remove. // Chain id to remove.
ChainID string `protobuf:"bytes,2,opt,name=chainID,proto3" json:"chainID,omitempty"` ChainID []byte `protobuf:"bytes,2,opt,name=chainID,proto3" json:"chainID,omitempty"`
} }
func (x *GetPolicyRequest_Body) Reset() { func (x *GetPolicyRequest_Body) Reset() {
@ -1123,11 +1123,11 @@ func (x *GetPolicyRequest_Body) GetNamespace() string {
return "" return ""
} }
func (x *GetPolicyRequest_Body) GetChainID() string { func (x *GetPolicyRequest_Body) GetChainID() []byte {
if x != nil { if x != nil {
return x.ChainID return x.ChainID
} }
return "" return nil
} }
type GetPolicyResponse_Body struct { type GetPolicyResponse_Body struct {
@ -1232,7 +1232,7 @@ type ListPoliciesResponse_Body struct {
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
// Chain ids. // Chain ids.
ChainIDs []string `protobuf:"bytes,1,rep,name=chainIDs,proto3" json:"chainIDs,omitempty"` ChainIDs [][]byte `protobuf:"bytes,1,rep,name=chainIDs,proto3" json:"chainIDs,omitempty"`
} }
func (x *ListPoliciesResponse_Body) Reset() { func (x *ListPoliciesResponse_Body) Reset() {
@ -1267,7 +1267,7 @@ func (*ListPoliciesResponse_Body) Descriptor() ([]byte, []int) {
return file_pkg_service_control_service_proto_rawDescGZIP(), []int{10, 0} return file_pkg_service_control_service_proto_rawDescGZIP(), []int{10, 0}
} }
func (x *ListPoliciesResponse_Body) GetChainIDs() []string { func (x *ListPoliciesResponse_Body) GetChainIDs() [][]byte {
if x != nil { if x != nil {
return x.ChainIDs return x.ChainIDs
} }
@ -1345,7 +1345,7 @@ var file_pkg_service_control_service_proto_rawDesc = []byte{
0x0a, 0x09, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x0a, 0x09, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x1c, 0x0a, 0x09, 0x6e,
0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09,
0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x68, 0x61, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x68, 0x61,
0x69, 0x6e, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x69, 0x6e, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69,
0x6e, 0x49, 0x44, 0x1a, 0x55, 0x0a, 0x04, 0x42, 0x6f, 0x64, 0x79, 0x12, 0x4d, 0x0a, 0x0a, 0x63, 0x6e, 0x49, 0x44, 0x1a, 0x55, 0x0a, 0x04, 0x42, 0x6f, 0x64, 0x79, 0x12, 0x4d, 0x0a, 0x0a, 0x63,
0x68, 0x61, 0x69, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32,
0x2d, 0x2e, 0x73, 0x33, 0x67, 0x77, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x52, 0x2d, 0x2e, 0x73, 0x33, 0x67, 0x77, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x52,
@ -1372,7 +1372,7 @@ var file_pkg_service_control_service_proto_rawDesc = []byte{
0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x1a, 0x3e, 0x0a, 0x04, 0x42, 0x6f, 0x64, 0x79, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x1a, 0x3e, 0x0a, 0x04, 0x42, 0x6f, 0x64, 0x79,
0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x01, 0x20, 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x52, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x18, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x18,
0x0a, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52,
0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x44, 0x22, 0xa2, 0x01, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x44, 0x22, 0xa2, 0x01, 0x0a, 0x11, 0x47, 0x65, 0x74,
0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x38, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x38,
0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x73, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x73,
@ -1405,7 +1405,7 @@ var file_pkg_service_control_service_proto_rawDesc = []byte{
0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65,
0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x1a, 0x22, 0x0a, 0x04, 0x42, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x1a, 0x22, 0x0a, 0x04, 0x42,
0x6f, 0x64, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x44, 0x73, 0x18, 0x6f, 0x64, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x44, 0x73, 0x18,
0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x44, 0x73, 0x2a, 0x01, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x44, 0x73, 0x2a,
0x57, 0x0a, 0x0c, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x57, 0x0a, 0x0c, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12,
0x1b, 0x0a, 0x17, 0x48, 0x45, 0x41, 0x4c, 0x54, 0x48, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x1b, 0x0a, 0x17, 0x48, 0x45, 0x41, 0x4c, 0x54, 0x48, 0x5f, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53,
0x5f, 0x55, 0x4e, 0x44, 0x45, 0x46, 0x49, 0x4e, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x5f, 0x55, 0x4e, 0x44, 0x45, 0x46, 0x49, 0x4e, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08,

View file

@ -104,7 +104,7 @@ message RemovePoliciesRequest {
// Namespace. // Namespace.
string namespace = 1; string namespace = 1;
// Chain id to remove. // Chain id to remove.
string chainID = 2; bytes chainID = 2;
} }
message Body { message Body {
@ -133,7 +133,7 @@ message GetPolicyRequest {
// Namespace. // Namespace.
string namespace = 1; string namespace = 1;
// Chain id to remove. // Chain id to remove.
string chainID = 2; bytes chainID = 2;
} }
Body body = 1; Body body = 1;
@ -171,7 +171,7 @@ message ListPoliciesRequest {
message ListPoliciesResponse { message ListPoliciesResponse {
message Body { message Body {
// Chain ids. // Chain ids.
repeated string chainIDs = 1; repeated bytes chainIDs = 1;
} }
Body body = 1; Body body = 1;

View file

@ -408,7 +408,7 @@ func (x *RemovePoliciesRequest_ChainInfo) StableSize() (size int) {
return 0 return 0
} }
size += proto.StringSize(1, x.Namespace) size += proto.StringSize(1, x.Namespace)
size += proto.StringSize(2, x.ChainID) size += proto.BytesSize(2, x.ChainID)
return size return size
} }
@ -429,7 +429,7 @@ func (x *RemovePoliciesRequest_ChainInfo) StableMarshal(buf []byte) []byte {
} }
var offset int var offset int
offset += proto.StringMarshal(1, buf[offset:], x.Namespace) offset += proto.StringMarshal(1, buf[offset:], x.Namespace)
offset += proto.StringMarshal(2, buf[offset:], x.ChainID) offset += proto.BytesMarshal(2, buf[offset:], x.ChainID)
return buf return buf
} }
@ -608,7 +608,7 @@ func (x *GetPolicyRequest_Body) StableSize() (size int) {
return 0 return 0
} }
size += proto.StringSize(1, x.Namespace) size += proto.StringSize(1, x.Namespace)
size += proto.StringSize(2, x.ChainID) size += proto.BytesSize(2, x.ChainID)
return size return size
} }
@ -629,7 +629,7 @@ func (x *GetPolicyRequest_Body) StableMarshal(buf []byte) []byte {
} }
var offset int var offset int
offset += proto.StringMarshal(1, buf[offset:], x.Namespace) offset += proto.StringMarshal(1, buf[offset:], x.Namespace)
offset += proto.StringMarshal(2, buf[offset:], x.ChainID) offset += proto.BytesMarshal(2, buf[offset:], x.ChainID)
return buf return buf
} }
@ -867,7 +867,7 @@ func (x *ListPoliciesResponse_Body) StableSize() (size int) {
if x == nil { if x == nil {
return 0 return 0
} }
size += proto.RepeatedStringSize(1, x.ChainIDs) size += proto.RepeatedBytesSize(1, x.ChainIDs)
return size return size
} }
@ -887,7 +887,7 @@ func (x *ListPoliciesResponse_Body) StableMarshal(buf []byte) []byte {
buf = make([]byte, x.StableSize()) buf = make([]byte, x.StableSize())
} }
var offset int var offset int
offset += proto.RepeatedStringMarshal(1, buf[offset:], x.ChainIDs) offset += proto.RepeatedBytesMarshal(1, buf[offset:], x.ChainIDs)
return buf return buf
} }