Skip to content

Commit

Permalink
Add changelog, move extract command outside of ledger
Browse files Browse the repository at this point in the history
  • Loading branch information
David Yan committed Jan 28, 2020
1 parent 2e4be05 commit 9a1230b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .changelog/2609.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Extract Ledger entities

We added a command to extract entities from existing signers, and a check to ensure
that the entity and signer public keys match.
This makes it so that a dummy entity cannot be used for signers backed by Ledger.
34 changes: 0 additions & 34 deletions go/oasis-node/cmd/signer/ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
package ledger

import (
"os"

"github.com/spf13/cobra"

ledgerCommon "github.com/oasislabs/oasis-core/go/common/ledger"
"github.com/oasislabs/oasis-core/go/common/logging"
cmdCommon "github.com/oasislabs/oasis-core/go/oasis-node/cmd/common"
cmdFlags "github.com/oasislabs/oasis-core/go/oasis-node/cmd/common/flags"
)

var (
Expand All @@ -23,14 +19,6 @@ var (
Short: "list available devices by address",
Run: doLedgerList,
}

extractCmd = &cobra.Command{
Use: "extract",
Short: "extract entity from device",
Run: doLedgerExtract,
}

logger = logging.GetLogger("cmd/signer/ledger")
)

func doLedgerList(cmd *cobra.Command, args []string) {
Expand All @@ -40,34 +28,12 @@ func doLedgerList(cmd *cobra.Command, args []string) {
ledgerCommon.ListDevices()
}

func doLedgerExtract(cmd *cobra.Command, args []string) {
if err := cmdCommon.Init(); err != nil {
cmdCommon.EarlyLogAndExit(err)
}
entityDir, err := cmdFlags.SignerDirOrPwd()
if err != nil {
logger.Error("failed to retrieve signer dir",
"err", err,
)
os.Exit(1)
}
if err := cmdCommon.ExtractEntity(cmdFlags.Signer(), entityDir); err != nil {
logger.Error("failed to extract entity",
"err", err,
)
os.Exit(1)
}
}

func Register(parentCmd *cobra.Command) {
for _, v := range []*cobra.Command{
listCmd,
extractCmd,
} {
ledgerCmd.AddCommand(v)
}

extractCmd.Flags().AddFlagSet(cmdFlags.SignerFlags)

parentCmd.AddCommand(ledgerCmd)
}
35 changes: 35 additions & 0 deletions go/oasis-node/cmd/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
package signer

import (
"os"

"github.com/spf13/cobra"

"github.com/oasislabs/oasis-core/go/common/logging"
cmdCommon "github.com/oasislabs/oasis-core/go/oasis-node/cmd/common"
cmdFlags "github.com/oasislabs/oasis-core/go/oasis-node/cmd/common/flags"
"github.com/oasislabs/oasis-core/go/oasis-node/cmd/signer/ledger"
)

Expand All @@ -12,14 +17,44 @@ var (
Use: "signer",
Short: "signer backend utilities",
}

extractCmd = &cobra.Command{
Use: "extract",
Short: "extract entity from signer",
Run: doEntityExtract,
}

logger = logging.GetLogger("cmd/signer")
)

func doEntityExtract(cmd *cobra.Command, args []string) {
if err := cmdCommon.Init(); err != nil {
cmdCommon.EarlyLogAndExit(err)
}
entityDir, err := cmdFlags.SignerDirOrPwd()
if err != nil {
logger.Error("failed to retrieve signer dir",
"err", err,
)
os.Exit(1)
}
if err := cmdCommon.ExtractEntity(cmdFlags.Signer(), entityDir); err != nil {
logger.Error("failed to extract entity",
"err", err,
)
os.Exit(1)
}
}

func Register(parentCmd *cobra.Command) {
for _, v := range []func(*cobra.Command){
ledger.Register,
} {
v(signerCmd)
}

extractCmd.Flags().AddFlagSet(cmdFlags.SignerFlags)

signerCmd.AddCommand(extractCmd)
parentCmd.AddCommand(signerCmd)
}

0 comments on commit 9a1230b

Please sign in to comment.