Merge pull request #609 from filecoin-project/feat/create-token

Add parameters for creating tokens
This commit is contained in:
Łukasz Magiera 2019-11-14 21:41:27 +01:00 committed by GitHub
commit b68f13480b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 6 deletions

View File

@ -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,24 @@ var authCreateAdminToken = &cli.Command{
ctx := ReqContext(cctx)
// TODO: Probably tell the user how powerful this token is
if !cctx.IsSet("perm") {
return errors.New("--perm flag not set")
}
token, err := napi.AuthNew(ctx, api.AllPermissions)
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)
}
// slice on [:idx] so for example: 'sign' gives you [read, write, sign]
token, err := napi.AuthNew(ctx, api.AllPermissions[:idx])
if err != nil {
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")}/>
</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