Skip to content

Commit

Permalink
support seed in tfrobot
Browse files Browse the repository at this point in the history
  • Loading branch information
rawdaGastan committed Sep 4, 2024
1 parent 6c91fae commit 8dbb80d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion tfrobot/internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/rs/zerolog/log"
"github.com/threefoldtech/tfgrid-sdk-go/grid-client/deployer"
tfrobot "github.com/threefoldtech/tfgrid-sdk-go/tfrobot/pkg/deployer"
"github.com/vedhavyas/go-subkey"
"golang.org/x/crypto/ssh"
"gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -48,7 +49,8 @@ func ParseConfig(file io.Reader, jsonFmt bool) (tfrobot.Config, error) {
return tfrobot.Config{}, err
}

if err := validateMnemonic(conf.Mnemonic); err != nil {
_, isSeedValid := subkey.DecodeHex(conf.Mnemonic)
if err := validateMnemonic(conf.Mnemonic); err != nil && !isSeedValid {
return tfrobot.Config{}, err
}

Expand Down
13 changes: 12 additions & 1 deletion tfrobot/internal/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,26 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/stretchr/testify/assert"
substrate "github.com/threefoldtech/tfchain/clients/tfchain-client-go"
"github.com/threefoldtech/tfgrid-sdk-go/grid-client/deployer"
tfrobot "github.com/threefoldtech/tfgrid-sdk-go/tfrobot/pkg/deployer"
"github.com/vedhavyas/go-subkey"
"gopkg.in/yaml.v3"
)

func TestParseConfig(t *testing.T) {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
validFlist := "https://hub.grid.tf/tf-official-apps/base:latest.flist"

// Alice identity
aliceIdentity, err := substrate.NewIdentityFromSr25519Phrase("//Alice")
assert.NoError(t, err)

keyPair, err := aliceIdentity.KeyPair()
assert.NoError(t, err)

seed := subkey.EncodeHex(keyPair.Seed())

confStruct := tfrobot.Config{
NodeGroups: []tfrobot.NodesGroup{
{
Expand Down Expand Up @@ -53,7 +64,7 @@ func TestParseConfig(t *testing.T) {
SSHKeys: map[string]string{
"example1": "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAklOUpkDHrfHY17SbrmTIpNLTGK9Tjom/BWDSUGPl+nafzlHDTYW7hdI4yZ5ew18JH4JW9jbhUFrviQzM7xlELEVf4h9lFX5QVkbPppSwg0cda3Pbv7kOdJ/MTyBlWXFCR+HAo3FXRitBqxiX1nKhXpHAZsMciLq8V6RjsNAQwdsdMFvSlVK/7XAt3FaoJoAsncM1Q9x5+3V0Ww68/eIFmb1zuUFljQJKprrX88XypNDvjYNby6vw/Pb0rwert/EnmZ+AW4OZPnTPI89ZPmVMLuayrD2cE86Z/il8b+gw3r3+1nKatmIkjn2so1d01QraTlMqVSsbxNrRFi9wrf+M7Q== schacon@mylaptop.local",
},
Mnemonic: "rival oyster defense garbage fame disease mask mail family wire village vibrant index fuel dolphin",
Mnemonic: seed,
Network: "dev",
}

Expand Down

0 comments on commit 8dbb80d

Please sign in to comment.