control: Extend api with ListOverrideDefinedTargets
#936
6 changed files with 113 additions and 18 deletions
|
@ -25,6 +25,7 @@ const (
|
|||
rpcListChainLocalOverrides = "ListChainLocalOverrides"
|
||||
rpcRemoveChainLocalOverride = "RemoveChainLocalOverride"
|
||||
rpcSealWriteCache = "SealWriteCache"
|
||||
rpcListTargetsLocalOverrides = "ListTargetsLocalOverrides"
|
||||
)
|
||||
|
||||
// HealthCheck executes ControlService.HealthCheck RPC.
|
||||
|
@ -240,6 +241,19 @@ func ListChainLocalOverrides(cli *client.Client, req *ListChainLocalOverridesReq
|
|||
return wResp.message, nil
|
||||
}
|
||||
|
||||
// ListTargetsLocalOverrides executes ControlService.ListTargetsLocalOverrides RPC.
|
||||
func ListTargetsLocalOverrides(cli *client.Client, req *ListTargetsLocalOverridesRequest, opts ...client.CallOption) (*ListTargetsLocalOverridesResponse, error) {
|
||||
wResp := newResponseWrapper[ListTargetsLocalOverridesResponse]()
|
||||
wReq := &requestWrapper{m: req}
|
||||
|
||||
err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceName, rpcListTargetsLocalOverrides), wReq, wResp, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return wResp.message, nil
|
||||
}
|
||||
|
||||
// RemoveChainLocalOverride executes ControlService.RemoveChainLocalOverride RPC.
|
||||
func GetChainLocalOverride(cli *client.Client, req *GetChainLocalOverrideRequest, opts ...client.CallOption) (*GetChainLocalOverrideResponse, error) {
|
||||
wResp := newResponseWrapper[GetChainLocalOverrideResponse]()
|
||||
|
|
|
@ -25,6 +25,29 @@ func apeTarget(chainTarget *control.ChainTarget) (engine.Target, error) {
|
|||
fmt.Errorf("target type is not supported: %s", chainTarget.GetType().String()).Error())
|
||||
}
|
||||
|
||||
func controlTarget(chainTarget *engine.Target) (control.ChainTarget, error) {
|
||||
switch chainTarget.Type {
|
||||
case engine.Container:
|
||||
return control.ChainTarget{
|
||||
Name: chainTarget.Name,
|
||||
Type: control.ChainTarget_CONTAINER,
|
||||
}, nil
|
||||
case engine.Namespace:
|
||||
// If namespace is empty, we take it for root namespace.
|
||||
nm := chainTarget.Name
|
||||
if nm == "root" {
|
||||
nm = ""
|
||||
}
|
||||
return control.ChainTarget{
|
||||
Name: nm,
|
||||
Type: control.ChainTarget_NAMESPACE,
|
||||
}, nil
|
||||
default:
|
||||
}
|
||||
return control.ChainTarget{}, status.Error(codes.InvalidArgument,
|
||||
fmt.Errorf("target type is not supported: %c", chainTarget.Type).Error())
|
||||
}
|
||||
|
||||
func (s *Server) AddChainLocalOverride(_ context.Context, req *control.AddChainLocalOverrideRequest) (*control.AddChainLocalOverrideResponse, error) {
|
||||
if err := s.isValidRequest(req); err != nil {
|
||||
return nil, status.Error(codes.PermissionDenied, err.Error())
|
||||
|
@ -157,6 +180,37 @@ func (s *Server) RemoveChainLocalOverride(_ context.Context, req *control.Remove
|
|||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *Server) ListTargetsLocalOverrides(_ context.Context, req *control.ListTargetsLocalOverridesRequest) (*control.ListTargetsLocalOverridesResponse, error) {
|
||||
if err := s.isValidRequest(req); err != nil {
|
||||
return nil, status.Error(codes.PermissionDenied, err.Error())
|
||||
}
|
||||
|
||||
apeChainName := apechain.Name(req.GetBody().GetChainName())
|
||||
apeTargets, err := s.localOverrideStorage.LocalStorage().ListOverrideDefinedTargets(apeChainName)
|
||||
if err != nil {
|
||||
return nil, status.Error(getCodeByLocalStorageErr(err), err.Error())
|
||||
}
|
||||
targets := make([]*control.ChainTarget, 0, len(apeTargets))
|
||||
for i := range apeTargets {
|
||||
target, err := controlTarget(&apeTargets[i])
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
targets = append(targets, &target)
|
||||
}
|
||||
|
||||
resp := &control.ListTargetsLocalOverridesResponse{
|
||||
Body: &control.ListTargetsLocalOverridesResponse_Body{
|
||||
Targets: targets,
|
||||
},
|
||||
}
|
||||
err = SignMessage(s.key, resp)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func getCodeByLocalStorageErr(err error) codes.Code {
|
||||
if errors.Is(err, engine.ErrChainNotFound) || errors.Is(err, engine.ErrChainNameNotFound) {
|
||||
return codes.NotFound
|
||||
|
|
BIN
pkg/services/control/service.pb.go
generated
BIN
pkg/services/control/service.pb.go
generated
Binary file not shown.
|
@ -57,6 +57,9 @@ service ControlService {
|
|||
// Remove local access policy engine overrides stored in the node by chaind id.
|
||||
rpc RemoveChainLocalOverride (RemoveChainLocalOverrideRequest) returns (RemoveChainLocalOverrideResponse);
|
||||
|
||||
// List targets of the local APE overrides stored in the node.
|
||||
rpc ListTargetsLocalOverrides (ListTargetsLocalOverridesRequest) returns (ListTargetsLocalOverridesResponse);
|
||||
|
||||
// Flush objects from write-cache and move it to degraded read only mode.
|
||||
rpc SealWriteCache(SealWriteCacheRequest) returns (SealWriteCacheResponse);
|
||||
}
|
||||
|
@ -505,6 +508,30 @@ message ListChainLocalOverridesResponse {
|
|||
Signature signature = 2;
|
||||
}
|
||||
|
||||
// ListTargetsLocalOverrides request.
|
||||
message ListTargetsLocalOverridesRequest {
|
||||
message Body {
|
||||
// Target for which the overrides are applied.
|
||||
string chainName = 1;
|
||||
}
|
||||
|
||||
Body body = 1;
|
||||
|
||||
Signature signature = 2;
|
||||
}
|
||||
|
||||
// ListTargetsLocalOverrides response.
|
||||
message ListTargetsLocalOverridesResponse {
|
||||
message Body {
|
||||
// The list of chain targets.
|
||||
repeated ChainTarget targets = 1;
|
||||
}
|
||||
|
||||
Body body = 1;
|
||||
|
||||
Signature signature = 2;
|
||||
}
|
||||
|
||||
message RemoveChainLocalOverrideRequest {
|
||||
message Body {
|
||||
// Target for which the overrides are applied.
|
||||
|
|
BIN
pkg/services/control/service_frostfs.pb.go
generated
BIN
pkg/services/control/service_frostfs.pb.go
generated
Binary file not shown.
BIN
pkg/services/control/service_grpc.pb.go
generated
BIN
pkg/services/control/service_grpc.pb.go
generated
Binary file not shown.
Loading…
Reference in a new issue