diff --git a/cli/auth.go b/cli/auth.go index 44287c4e0..0b40dc573 100644 --- a/cli/auth.go +++ b/cli/auth.go @@ -1,6 +1,7 @@ package cli import ( + "errors" "fmt" "gopkg.in/urfave/cli.v2" @@ -17,8 +18,15 @@ var authCmd = &cli.Command{ } var authCreateAdminToken = &cli.Command{ - Name: "create-admin-token", - Usage: "Create admin token", + 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 := GetFullNodeAPI(cctx) if err != nil { @@ -28,9 +36,25 @@ var authCreateAdminToken = &cli.Command{ ctx := ReqContext(cctx) + if !cctx.IsSet("perm") { + return errors.New("--perm flag not set") + } + + perm := cctx.String("perm") + idx := -1 + for i, p := range api.AllPermissions { + if perm == p { + idx = i + } + } + + if idx == -1 { + return fmt.Errorf("--perm flag has to be one of: %s", api.AllPermissions) + } + // TODO: Probably tell the user how powerful this token is - token, err := napi.AuthNew(ctx, api.AllPermissions) + token, err := napi.AuthNew(ctx, api.AllPermissions[:idx]) if err != nil { return err } diff --git a/lotuspond/front/src/NodeIndex.js b/lotuspond/front/src/NodeIndex.js index 676326c64..059d562f8 100644 --- a/lotuspond/front/src/NodeIndex.js +++ b/lotuspond/front/src/NodeIndex.js @@ -93,7 +93,7 @@ class Index extends React.Component { + RPC:
lotus auth create-admin-token
): {this.tokenOk()}
+ Token (lotus auth create-token --perm admin
): {this.tokenOk()}