github.com/celestiaorg/celestia-node@v0.15.0-beta.1/nodebuilder/node/cmd/node.go (about) 1 package cmd 2 3 import ( 4 "errors" 5 "strings" 6 7 "github.com/filecoin-project/go-jsonrpc/auth" 8 "github.com/spf13/cobra" 9 10 cmdnode "github.com/celestiaorg/celestia-node/cmd" 11 ) 12 13 func init() { 14 Cmd.AddCommand(nodeInfoCmd, logCmd, verifyCmd, authCmd) 15 } 16 17 var Cmd = &cobra.Command{ 18 Use: "node [command]", 19 Short: "Allows administrating running node.", 20 Args: cobra.NoArgs, 21 PersistentPreRunE: cmdnode.InitClient, 22 } 23 24 var nodeInfoCmd = &cobra.Command{ 25 Use: "info", 26 Args: cobra.NoArgs, 27 Short: "Returns administrative information about the node.", 28 RunE: func(c *cobra.Command, args []string) error { 29 client, err := cmdnode.ParseClientFromCtx(c.Context()) 30 if err != nil { 31 return err 32 } 33 defer client.Close() 34 35 info, err := client.Node.Info(c.Context()) 36 return cmdnode.PrintOutput(info, err, nil) 37 }, 38 } 39 40 var logCmd = &cobra.Command{ 41 Use: "log-level", 42 Args: cobra.MinimumNArgs(1), 43 Short: "Sets log level for module.", 44 Long: "Allows to set log level for module to in format <module>:<level>" + 45 "`DEBUG, INFO, WARN, ERROR, DPANIC, PANIC, FATAL and their lower-case forms`.\n" + 46 "To set all modules to a particular level `*:<log.level>` should be passed", 47 RunE: func(c *cobra.Command, args []string) error { 48 client, err := cmdnode.ParseClientFromCtx(c.Context()) 49 if err != nil { 50 return err 51 } 52 defer client.Close() 53 54 for _, ll := range args { 55 params := strings.Split(ll, ":") 56 if len(params) != 2 { 57 return errors.New("cmd: log-level arg must be in form <module>:<level>," + 58 "e.g. pubsub:debug") 59 } 60 61 if err := client.Node.LogLevelSet(c.Context(), params[0], params[1]); err != nil { 62 return err 63 } 64 } 65 return nil 66 }, 67 } 68 69 var verifyCmd = &cobra.Command{ 70 Use: "permissions", 71 Args: cobra.ExactArgs(1), 72 Short: "Returns the permissions assigned to the given token.", 73 74 RunE: func(c *cobra.Command, args []string) error { 75 client, err := cmdnode.ParseClientFromCtx(c.Context()) 76 if err != nil { 77 return err 78 } 79 defer client.Close() 80 81 perms, err := client.Node.AuthVerify(c.Context(), args[0]) 82 return cmdnode.PrintOutput(perms, err, nil) 83 }, 84 } 85 86 var authCmd = &cobra.Command{ 87 Use: "set-permissions", 88 Args: cobra.MinimumNArgs(1), 89 Short: "Signs and returns a new token with the given permissions.", 90 RunE: func(c *cobra.Command, args []string) error { 91 client, err := cmdnode.ParseClientFromCtx(c.Context()) 92 if err != nil { 93 return err 94 } 95 defer client.Close() 96 97 perms := make([]auth.Permission, len(args)) 98 for i, p := range args { 99 perms[i] = (auth.Permission)(p) 100 } 101 102 result, err := client.Node.AuthNew(c.Context(), perms) 103 return cmdnode.PrintOutput(result, err, nil) 104 }, 105 }