Add parameters for creating tokens
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
parent
c20aaf3856
commit
1ae611b21d
30
cli/auth.go
30
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
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ class Index extends React.Component {
|
||||
+ RPC:<input defaultValue={"ws://127.0.0.1:1234/rpc/v0"} onChange={this.update("rpcUrl")}/>
|
||||
</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>
|
||||
@ -107,4 +107,4 @@ class Index extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
export default Index
|
||||
export default Index
|
||||
|
Loading…
Reference in New Issue
Block a user