do the auth command the right way
This commit is contained in:
parent
9bdbc5daf1
commit
2322c42fd0
@ -28,7 +28,7 @@ var authCreateAdminToken = &cli.Command{
|
|||||||
},
|
},
|
||||||
|
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
napi, closer, err := GetFullNodeAPI(cctx)
|
napi, closer, err := GetAPI(cctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"gopkg.in/urfave/cli.v2"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api/apistruct"
|
|
||||||
lcli "github.com/filecoin-project/lotus/cli"
|
|
||||||
)
|
|
||||||
|
|
||||||
var authCmd = &cli.Command{
|
|
||||||
Name: "auth",
|
|
||||||
Usage: "Manage RPC permissions",
|
|
||||||
Subcommands: []*cli.Command{
|
|
||||||
authCreateAdminToken,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var authCreateAdminToken = &cli.Command{
|
|
||||||
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 := lcli.GetStorageMinerAPI(cctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer closer()
|
|
||||||
|
|
||||||
ctx := lcli.ReqContext(cctx)
|
|
||||||
|
|
||||||
if !cctx.IsSet("perm") {
|
|
||||||
return errors.New("--perm flag not set")
|
|
||||||
}
|
|
||||||
|
|
||||||
perm := cctx.String("perm")
|
|
||||||
idx := 0
|
|
||||||
for i, p := range apistruct.AllPermissions {
|
|
||||||
if perm == p {
|
|
||||||
idx = i + 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if idx == 0 {
|
|
||||||
return fmt.Errorf("--perm flag has to be one of: %s", apistruct.AllPermissions)
|
|
||||||
}
|
|
||||||
|
|
||||||
// slice on [:idx] so for example: 'sign' gives you [read, write, sign]
|
|
||||||
token, err := napi.AuthNew(ctx, apistruct.AllPermissions[:idx])
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Log in audit log when it is implemented
|
|
||||||
|
|
||||||
fmt.Println(string(token))
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
}
|
|
@ -8,6 +8,7 @@ import (
|
|||||||
"gopkg.in/urfave/cli.v2"
|
"gopkg.in/urfave/cli.v2"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
|
lcli "github.com/filecoin-project/lotus/cli"
|
||||||
"github.com/filecoin-project/lotus/node/repo"
|
"github.com/filecoin-project/lotus/node/repo"
|
||||||
"github.com/filecoin-project/lotus/tracing"
|
"github.com/filecoin-project/lotus/tracing"
|
||||||
)
|
)
|
||||||
@ -21,7 +22,6 @@ func main() {
|
|||||||
logging.SetLogLevel("swarm", "WARN")
|
logging.SetLogLevel("swarm", "WARN")
|
||||||
|
|
||||||
local := []*cli.Command{
|
local := []*cli.Command{
|
||||||
authCmd,
|
|
||||||
runCmd,
|
runCmd,
|
||||||
initCmd,
|
initCmd,
|
||||||
infoCmd,
|
infoCmd,
|
||||||
@ -67,7 +67,7 @@ func main() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
Commands: local,
|
Commands: append(local, lcli.Commands...),
|
||||||
}
|
}
|
||||||
app.Setup()
|
app.Setup()
|
||||||
app.Metadata["repoType"] = repo.StorageMiner
|
app.Metadata["repoType"] = repo.StorageMiner
|
||||||
|
Loading…
Reference in New Issue
Block a user