[#787] cli: Add vub for control ir commands

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-11-07 17:35:09 +03:00
parent bdfa523487
commit 5466e88444
5 changed files with 38 additions and 5 deletions

View file

@ -1,6 +1,9 @@
package control package control
import "github.com/spf13/cobra" import (
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
"github.com/spf13/cobra"
)
var irCmd = &cobra.Command{ var irCmd = &cobra.Command{
Use: "ir", Use: "ir",
@ -19,3 +22,13 @@ func initControlIRCmd() {
initControlIRHealthCheckCmd() initControlIRHealthCheckCmd()
initControlIRRemoveContainerCmd() initControlIRRemoveContainerCmd()
} }
func printVUB(cmd *cobra.Command, vub uint32) {
cmd.Printf("Transaction's valid until block is %d\n", vub)
}
func parseVUB(cmd *cobra.Command) uint32 {
vub, err := cmd.Flags().GetUint32(irFlagNameVUB)
commonCmd.ExitOnErr(cmd, "invalid valid until block value: %w", err)
return vub
}

View file

@ -29,7 +29,7 @@ To check removal status "frostfs-cli container list" command can be used.`,
} }
func initControlIRRemoveContainerCmd() { func initControlIRRemoveContainerCmd() {
initControlFlags(removeContainerCmd) initControlIRFlags(removeContainerCmd)
flags := removeContainerCmd.Flags() flags := removeContainerCmd.Flags()
flags.String(commonflags.CIDFlag, "", commonflags.CIDFlagUsage) flags.String(commonflags.CIDFlag, "", commonflags.CIDFlagUsage)
@ -60,6 +60,7 @@ func removeContainer(cmd *cobra.Command, _ []string) {
} else { } else {
cmd.Println("User containers sheduled to removal") cmd.Println("User containers sheduled to removal")
} }
printVUB(cmd, resp.GetBody().GetVub())
} }
func prepareRemoveContainerRequest(cmd *cobra.Command) *ircontrol.RemoveContainerRequest { func prepareRemoveContainerRequest(cmd *cobra.Command) *ircontrol.RemoveContainerRequest {
@ -90,5 +91,8 @@ func prepareRemoveContainerRequest(cmd *cobra.Command) *ircontrol.RemoveContaine
commonCmd.ExitOnErr(cmd, "invalid container ID: %w", containerID.DecodeString(cidStr)) commonCmd.ExitOnErr(cmd, "invalid container ID: %w", containerID.DecodeString(cidStr))
req.Body.ContainerId = containerID[:] req.Body.ContainerId = containerID[:]
} }
req.Body.Vub = parseVUB(cmd)
return req return req
} }

View file

@ -20,7 +20,7 @@ var removeNodeCmd = &cobra.Command{
} }
func initControlIRRemoveNodeCmd() { func initControlIRRemoveNodeCmd() {
initControlFlags(removeNodeCmd) initControlIRFlags(removeNodeCmd)
flags := removeNodeCmd.Flags() flags := removeNodeCmd.Flags()
flags.String("node", "", "Node public key as a hex string") flags.String("node", "", "Node public key as a hex string")
@ -41,6 +41,7 @@ func removeNode(cmd *cobra.Command, _ []string) {
req := new(ircontrol.RemoveNodeRequest) req := new(ircontrol.RemoveNodeRequest)
req.SetBody(&ircontrol.RemoveNodeRequest_Body{ req.SetBody(&ircontrol.RemoveNodeRequest_Body{
Key: nodeKey, Key: nodeKey,
Vub: parseVUB(cmd),
}) })
commonCmd.ExitOnErr(cmd, "could not sign request: %w", ircontrolsrv.SignMessage(pk, req)) commonCmd.ExitOnErr(cmd, "could not sign request: %w", ircontrolsrv.SignMessage(pk, req))
@ -55,4 +56,5 @@ func removeNode(cmd *cobra.Command, _ []string) {
verifyResponse(cmd, resp.GetSignature(), resp.GetBody()) verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
cmd.Println("Node removed") cmd.Println("Node removed")
printVUB(cmd, resp.GetBody().GetVub())
} }

View file

@ -17,7 +17,7 @@ var tickEpochCmd = &cobra.Command{
} }
func initControlIRTickEpochCmd() { func initControlIRTickEpochCmd() {
initControlFlags(tickEpochCmd) initControlIRFlags(tickEpochCmd)
} }
func tickEpoch(cmd *cobra.Command, _ []string) { func tickEpoch(cmd *cobra.Command, _ []string) {
@ -25,7 +25,9 @@ func tickEpoch(cmd *cobra.Command, _ []string) {
c := getClient(cmd, pk) c := getClient(cmd, pk)
req := new(ircontrol.TickEpochRequest) req := new(ircontrol.TickEpochRequest)
req.SetBody(new(ircontrol.TickEpochRequest_Body)) req.SetBody(&ircontrol.TickEpochRequest_Body{
Vub: parseVUB(cmd),
})
err := ircontrolsrv.SignMessage(pk, req) err := ircontrolsrv.SignMessage(pk, req)
commonCmd.ExitOnErr(cmd, "could not sign request: %w", err) commonCmd.ExitOnErr(cmd, "could not sign request: %w", err)
@ -40,4 +42,5 @@ func tickEpoch(cmd *cobra.Command, _ []string) {
verifyResponse(cmd, resp.GetSignature(), resp.GetBody()) verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
cmd.Println("Epoch tick requested") cmd.Println("Epoch tick requested")
printVUB(cmd, resp.GetBody().GetVub())
} }

View file

@ -14,6 +14,10 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
const (
irFlagNameVUB = "vub"
)
func initControlFlags(cmd *cobra.Command) { func initControlFlags(cmd *cobra.Command) {
ff := cmd.Flags() ff := cmd.Flags()
ff.StringP(commonflags.WalletPath, commonflags.WalletPathShorthand, commonflags.WalletPathDefault, commonflags.WalletPathUsage) ff.StringP(commonflags.WalletPath, commonflags.WalletPathShorthand, commonflags.WalletPathDefault, commonflags.WalletPathUsage)
@ -22,6 +26,13 @@ func initControlFlags(cmd *cobra.Command) {
ff.DurationP(commonflags.Timeout, commonflags.TimeoutShorthand, commonflags.TimeoutDefault, commonflags.TimeoutUsage) ff.DurationP(commonflags.Timeout, commonflags.TimeoutShorthand, commonflags.TimeoutDefault, commonflags.TimeoutUsage)
} }
func initControlIRFlags(cmd *cobra.Command) {
initControlFlags(cmd)
ff := cmd.Flags()
ff.Uint32(irFlagNameVUB, 0, "Valid until block value for notary transaction")
}
func signRequest(cmd *cobra.Command, pk *ecdsa.PrivateKey, req controlSvc.SignedMessage) { func signRequest(cmd *cobra.Command, pk *ecdsa.PrivateKey, req controlSvc.SignedMessage) {
err := controlSvc.SignMessage(pk, req) err := controlSvc.SignMessage(pk, req)
commonCmd.ExitOnErr(cmd, "could not sign request: %w", err) commonCmd.ExitOnErr(cmd, "could not sign request: %w", err)