Merge pull request #609 from filecoin-project/feat/create-token
Add parameters for creating tokens
This commit is contained in:
commit
b68f13480b
31
cli/auth.go
31
cli/auth.go
@ -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,24 @@ var authCreateAdminToken = &cli.Command{
|
|||||||
|
|
||||||
ctx := ReqContext(cctx)
|
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 {
|
if err != nil {
|
||||||
return err
|
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")}/>
|
+ 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
|
||||||
|
Loading…
Reference in New Issue
Block a user