60e9de8d63
In previous implementation turning to maintenance mode using NeoFS CLI required NeoFS API endpoint. This was not convenient from the user perspective. It's worth to move networks settings' check to the server side. Add `force_maintenance` field to `SetNetmapStatusRequest.Body` message of Control API. Add `force` flag to `neofs-cli control set-status` command which sets corresponding field in the requests body if status is `maintenance`. Force flag is ignored for any other status. Signed-off-by: Leonard Lyubich <ctulhurider@gmail.com>
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package control
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
// SetNetmapStatus sets node status in NeoFS network.
|
|
//
|
|
// If request is unsigned or signed by disallowed key, permission error returns.
|
|
func (s *Server) SetNetmapStatus(ctx context.Context, req *control.SetNetmapStatusRequest) (*control.SetNetmapStatusResponse, error) {
|
|
// verify request
|
|
if err := s.isValidRequest(req); err != nil {
|
|
return nil, status.Error(codes.PermissionDenied, err.Error())
|
|
}
|
|
|
|
var err error
|
|
bodyReq := req.GetBody()
|
|
st := bodyReq.GetStatus()
|
|
force := bodyReq.GetForceMaintenance()
|
|
|
|
if force {
|
|
if st != control.NetmapStatus_MAINTENANCE {
|
|
return nil, status.Errorf(codes.InvalidArgument,
|
|
"force_maintenance MUST be set for %s status only", control.NetmapStatus_MAINTENANCE)
|
|
}
|
|
|
|
err = s.nodeState.ForceMaintenance()
|
|
} else {
|
|
err = s.nodeState.SetNetmapStatus(st)
|
|
}
|
|
|
|
if err != nil {
|
|
return nil, status.Error(codes.Aborted, err.Error())
|
|
}
|
|
|
|
// create and fill response
|
|
resp := new(control.SetNetmapStatusResponse)
|
|
|
|
body := new(control.SetNetmapStatusResponse_Body)
|
|
resp.SetBody(body)
|
|
|
|
// sign the response
|
|
if err := SignMessage(s.key, resp); err != nil {
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
}
|
|
|
|
return resp, nil
|
|
}
|