Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt: help information &remove duplicate function cmds / 准确的帮助信息,删除重复功能命令 #104

Merged
merged 1 commit into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 7 additions & 54 deletions cli/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,21 @@ import (
"errors"
"fmt"

"github.com/urfave/cli/v2"

"github.com/filecoin-project/venus-wallet/cli/helper"

"github.com/filecoin-project/venus/venus-shared/api/permission"
"github.com/urfave/cli/v2"
)

var authCmd = &cli.Command{
Name: "auth",
Usage: "Manage RPC permissions",
Subcommands: []*cli.Command{
authCreateAdminToken,
authApiInfoToken,
},
}

var authCreateAdminToken = &cli.Command{
Name: "create-token",
Usage: "Create token",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "perm",
Usage: "permission to assign to the token, one of: read, write, sign, admin",
},
},

Action: func(cctx *cli.Context) error {
napi, closer, err := helper.GetAPI(cctx)
if err != nil {
return err
}
defer closer()

ctx := helper.ReqContext(cctx)

if !cctx.IsSet("perm") {
return errors.New("--perm flag not set")
}

perm := cctx.String("perm")
idx := 0
for i, p := range permission.AllPermissions {
if perm == p {
idx = i + 1
}
}

if idx == 0 {
return fmt.Errorf("--perm flag has to be one of: %s", permission.AllPermissions)
}

// slice on [:idx] so for example: 'sign' gives you [read, write, sign]
token, err := napi.AuthNew(ctx, permission.AllPermissions[:idx])
if err != nil {
return err
}

// TODO: Log in audit log when it is implemented

fmt.Println(string(token))
return nil
},
}

var authApiInfoToken = &cli.Command{
Name: "api-info",
Usage: "Get token with API info required to connect to this node",
Expand All @@ -77,7 +30,7 @@ var authApiInfoToken = &cli.Command{
},

Action: func(cctx *cli.Context) error {
napi, closer, err := helper.GetAPI(cctx)
api, closer, err := helper.GetAPI(cctx)
if err != nil {
return err
}
Expand All @@ -102,16 +55,16 @@ var authApiInfoToken = &cli.Command{
}

// slice on [:idx] so for example: 'sign' gives you [read, write, sign]
token, err := napi.AuthNew(ctx, permission.AllPermissions[:idx])
token, err := api.AuthNew(ctx, permission.AllPermissions[:idx])
if err != nil {
return err
}

ainfo, err := helper.GetAPIInfo(cctx)
apiInfo, err := helper.GetAPIInfo(cctx)
if err != nil {
return fmt.Errorf("could not get API info: %w", err)
}
fmt.Printf("%s:%s\n", string(token), ainfo.Addr)
fmt.Printf("%s:%s\n", string(token), apiInfo.Addr)
return nil
},
}
2 changes: 1 addition & 1 deletion cli/cli_strategy/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

var StrategyCmd = &cli.Command{
Name: "strategy",
Usage: "Manage logging",
Usage: "Manage the signing strategy",
Aliases: []string{"st"},
Subcommands: []*cli.Command{
//read
Expand Down
8 changes: 4 additions & 4 deletions cli/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var walletSetPassword = &cli.Command{

var walletUnlock = &cli.Command{
Name: "unlock",
Usage: "unlock the wallet and release private key",
Usage: "Unlock the wallet private key, so that it can be used for signing",
Action: func(cctx *cli.Context) error {
api, closer, err := helper.GetFullAPI(cctx)
if err != nil {
Expand Down Expand Up @@ -104,7 +104,7 @@ var walletLock = &cli.Command{

var walletLockState = &cli.Command{
Name: "lock-state",
Usage: "unlock the wallet and release private key",
Usage: "View the status of the key lock",
Action: func(cctx *cli.Context) error {
api, closer, err := helper.GetFullAPI(cctx)
if err != nil {
Expand Down Expand Up @@ -301,7 +301,7 @@ var walletImport = &cli.Command{

var walletSign = &cli.Command{
Name: "sign",
Usage: "sign a message",
Usage: "sign a hex-encoded message",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "msg-type",
Expand Down Expand Up @@ -360,7 +360,7 @@ var walletSign = &cli.Command{

var walletDel = &cli.Command{
Name: "del",
Usage: "del a wallet and message",
Usage: "Del a wallet private key",
ArgsUsage: "<address>",
Action: func(cctx *cli.Context) error {
if !cctx.Args().Present() || cctx.NArg() != 1 {
Expand Down
9 changes: 5 additions & 4 deletions cli/wallet_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package cli
import (
"fmt"

"github.com/filecoin-project/venus-wallet/cli/helper"
"github.com/urfave/cli/v2"

"github.com/filecoin-project/venus-wallet/cli/helper"
)

var supportCmds = &cli.Command{
Name: "support",
Aliases: []string{"support"},
Usage: "tell upstream which account to support",
ArgsUsage: "account",
Usage: "Add an account that can be signed with the private key",
ArgsUsage: "<account>",
Action: func(cctx *cli.Context) error {
api, closer, err := helper.GetFullAPI(cctx)
if err != nil {
Expand All @@ -22,6 +22,7 @@ var supportCmds = &cli.Command{
if cctx.NArg() != 1 {
return fmt.Errorf("must specify account to support")
}

return api.AddSupportAccount(ctx, cctx.Args().Get(0))
},
}