[#9999] adm: Add maintenance zombie
commands
Some checks failed
DCO action / DCO (pull_request) Successful in 33s
Build / Build Components (pull_request) Successful in 1m29s
Vulncheck / Vulncheck (pull_request) Failing after 1m20s
Tests and linters / Staticcheck (pull_request) Successful in 2m34s
Tests and linters / Lint (pull_request) Successful in 2m59s
Tests and linters / Tests with -race (pull_request) Successful in 3m7s
Tests and linters / gopls check (pull_request) Successful in 3m54s
Tests and linters / Tests (pull_request) Failing after 41s
Some checks failed
DCO action / DCO (pull_request) Successful in 33s
Build / Build Components (pull_request) Successful in 1m29s
Vulncheck / Vulncheck (pull_request) Failing after 1m20s
Tests and linters / Staticcheck (pull_request) Successful in 2m34s
Tests and linters / Lint (pull_request) Successful in 2m59s
Tests and linters / Tests with -race (pull_request) Successful in 3m7s
Tests and linters / gopls check (pull_request) Successful in 3m54s
Tests and linters / Tests (pull_request) Failing after 41s
Change-Id: I2e85169849e2b9b7f44817b93283fa2f2b903676 Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
5a2a877cca
commit
4cb32170f3
11 changed files with 1001 additions and 0 deletions
70
cmd/frostfs-adm/internal/modules/maintenance/zombie/key.go
Normal file
70
cmd/frostfs-adm/internal/modules/maintenance/zombie/key.go
Normal file
|
@ -0,0 +1,70 @@
|
|||
package zombie
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config"
|
||||
nodeconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/node"
|
||||
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
||||
"github.com/nspcc-dev/neo-go/cli/flags"
|
||||
"github.com/nspcc-dev/neo-go/cli/input"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func getPrivateKey(cmd *cobra.Command, appCfg *config.Config) *ecdsa.PrivateKey {
|
||||
keyDesc := viper.GetString(walletFlag)
|
||||
if keyDesc == "" {
|
||||
return &nodeconfig.Key(appCfg).PrivateKey
|
||||
}
|
||||
data, err := os.ReadFile(keyDesc)
|
||||
commonCmd.ExitOnErr(cmd, "open wallet file: %w", err)
|
||||
|
||||
priv, err := keys.NewPrivateKeyFromBytes(data)
|
||||
if err != nil {
|
||||
w, err := wallet.NewWalletFromFile(keyDesc)
|
||||
commonCmd.ExitOnErr(cmd, "provided key is incorrect, only wallet or binary key supported: %w", err)
|
||||
return FromWallet(cmd, w, viper.GetString(addressFlag))
|
||||
}
|
||||
return &priv.PrivateKey
|
||||
}
|
||||
|
||||
func FromWallet(cmd *cobra.Command, w *wallet.Wallet, addrStr string) *ecdsa.PrivateKey {
|
||||
var (
|
||||
addr util.Uint160
|
||||
err error
|
||||
)
|
||||
|
||||
if addrStr == "" {
|
||||
addr = w.GetChangeAddress()
|
||||
} else {
|
||||
addr, err = flags.ParseAddress(addrStr)
|
||||
commonCmd.ExitOnErr(cmd, "--address option must be specified and valid: %w", err)
|
||||
}
|
||||
|
||||
acc := w.GetAccount(addr)
|
||||
if acc == nil {
|
||||
commonCmd.ExitOnErr(cmd, "--address option must be specified and valid: %w", fmt.Errorf("can't find wallet account for %s", addrStr))
|
||||
}
|
||||
|
||||
pass, err := getPassword()
|
||||
commonCmd.ExitOnErr(cmd, "invalid password for the encrypted key: %w", err)
|
||||
|
||||
commonCmd.ExitOnErr(cmd, "can't decrypt account: %w", acc.Decrypt(pass, keys.NEP2ScryptParams()))
|
||||
|
||||
return &acc.PrivateKey().PrivateKey
|
||||
}
|
||||
|
||||
func getPassword() (string, error) {
|
||||
// this check allows empty passwords
|
||||
if viper.IsSet("password") {
|
||||
return viper.GetString("password"), nil
|
||||
}
|
||||
|
||||
return input.ReadPassword("Enter password > ")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue