Skip to content

Commit

Permalink
feat(rpc): add admin cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Sep 14, 2023
1 parent 0794b5d commit ff9f570
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 50 deletions.
88 changes: 88 additions & 0 deletions cmd/celestia/admin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package main

import (
"strings"

"github.com/filecoin-project/go-jsonrpc/auth"
"github.com/spf13/cobra"

"github.com/celestiaorg/celestia-node/cmd"
)

var nodeInfoCmd = &cobra.Command{
Use: "node.info",
Args: cobra.NoArgs,
Short: "Returns administrative information about the node.",
RunE: func(c *cobra.Command, args []string) error {
client, err := rpcClient(c.Context())
if err != nil {
return err
}
info, err := client.Node.Info(c.Context())
return printOutput(info, err, nil)
},
}

var logCmd = &cobra.Command{
Use: cmd.LogLevelFlag,
Args: cobra.MinimumNArgs(1),
Short: "Allows to set log level for module to in format <module>:<level>" +
"`DEBUG, INFO, WARN, ERROR, DPANIC, PANIC, FATAL and their lower-case forms`.\n" +
"Log level will be set for all modules in case if only single log level will be passed.",
RunE: func(c *cobra.Command, args []string) error {
client, err := rpcClient(c.Context())
if err != nil {
return err
}

for _, ll := range args {
params := strings.Split(ll, ":")
if len(params) != 2 {
return client.Node.LogLevelSet(c.Context(), "*", args[0])
}

if err = client.Node.LogLevelSet(c.Context(), params[0], params[1]); err != nil {
return err
}
}
return nil
},
}

var verifyCmd = &cobra.Command{
Use: "permissions",
Args: cobra.ExactArgs(1),
Short: "Returns the permissions assigned to the given token.",

RunE: func(c *cobra.Command, args []string) error {
client, err := rpcClient(c.Context())
if err != nil {
return err
}

perms, err := client.Node.AuthVerify(c.Context(), args[0])
return printOutput(perms, err, nil)
},
}

var authCmd = &cobra.Command{
Use: "set.permissions",
Args: cobra.ExactArgs(1),
Short: "Signs and returns a new token with the given permissions in a format `<perm1>,<perm2>`.",
RunE: func(c *cobra.Command, args []string) error {
client, err := rpcClient(c.Context())
if err != nil {
return err
}

params := strings.Split(args[0], ":")

perms := make([]auth.Permission, len(params))
for i, p := range params {
perms[i] = (auth.Permission)(p)
}

result, err := client.Node.AuthNew(c.Context(), perms)
return printOutput(result, err, nil)
},
}
48 changes: 0 additions & 48 deletions cmd/celestia/logs.go

This file was deleted.

4 changes: 2 additions & 2 deletions cmd/celestia/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/celestiaorg/celestia-node/state"
)

const authEnvKey = "CELESTIA_NODE_AUTH_TOKEN" //nolint:gosec
const authEnvKey = "CELESTIA_NODE_AUTH_TOKEN"

var requestURL string
var authTokenFlag string
Expand Down Expand Up @@ -60,7 +60,7 @@ func init() {
false,
"Print JSON-RPC request along with the response",
)
rpcCmd.AddCommand(logCmd, logModuleCmd)
rpcCmd.AddCommand(nodeInfoCmd, logCmd, verifyCmd, authCmd)
rpcCmd.AddCommand(blobCmd)
rpcCmd.AddCommand(p2pCmd)
rpcCmd.AddCommand(dasCmd)
Expand Down

0 comments on commit ff9f570

Please sign in to comment.