Add parameters for creating tokens

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2019-11-14 21:19:52 +01:00
parent c20aaf3856
commit 1ae611b21d
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA
2 changed files with 29 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package cli package cli
import ( import (
"errors"
"fmt" "fmt"
"gopkg.in/urfave/cli.v2" "gopkg.in/urfave/cli.v2"
@ -17,8 +18,15 @@ var authCmd = &cli.Command{
} }
var authCreateAdminToken = &cli.Command{ var authCreateAdminToken = &cli.Command{
Name: "create-admin-token", Name: "create-token",
Usage: "Create admin 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 { Action: func(cctx *cli.Context) error {
napi, closer, err := GetFullNodeAPI(cctx) napi, closer, err := GetFullNodeAPI(cctx)
if err != nil { if err != nil {
@ -28,9 +36,25 @@ var authCreateAdminToken = &cli.Command{
ctx := ReqContext(cctx) 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 // 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 { if err != nil {
return err return err
} }

View File

@ -93,7 +93,7 @@ class Index extends React.Component {
+ RPC:<input defaultValue={"ws://127.0.0.1:1234/rpc/v0"} onChange={this.update("rpcUrl")}/> + RPC:<input defaultValue={"ws://127.0.0.1:1234/rpc/v0"} onChange={this.update("rpcUrl")}/>
</div> </div>
<div> <div>
Token (<code>lotus auth create-admin-token</code>): <input onChange={this.update("rpcToken")}/>{this.tokenOk()} Token (<code>lotus auth create-token --perm admin</code>): <input onChange={this.update("rpcToken")}/>{this.tokenOk()}
</div> </div>
</div> </div>
</div> </div>
@ -107,4 +107,4 @@ class Index extends React.Component {
} }
} }
export default Index export default Index