permission: changed the signature of IsNodePermissioned to avoid passing ctx. Removed hardcoding of permission-config.json.

This commit is contained in:
vsmk98 2019-08-14 10:54:13 +08:00
parent e9a05f63e7
commit b53841d1d7
4 changed files with 7 additions and 7 deletions

View File

@ -162,7 +162,7 @@ func makeFullNode(ctx *cli.Context) *node.Node {
ethChan := utils.RegisterEthService(stack, &cfg.Eth)
if utils.IsPermissionEnabled(ctx) {
if utils.IsPermissionEnabled(cfg.Node.DataDir, cfg.Node.EnableNodePermission) {
RegisterPermissionService(ctx, stack)
}

View File

@ -344,7 +344,7 @@ func startNode(ctx *cli.Context, stack *node.Node) {
}()
//initialize permission as we can create eth client only after the node and RPC are started
if utils.IsPermissionEnabled(ctx) {
if utils.IsPermissionEnabled(stack.Server().DataDir, stack.Server().EnableNodePermission) {
permission.StartPermissionService(stack)
}

View File

@ -20,7 +20,7 @@ package utils
import (
"compress/gzip"
"fmt"
"gopkg.in/urfave/cli.v1"
"github.com/ethereum/go-ethereum/params"
"io"
"os"
"os/signal"
@ -65,10 +65,9 @@ func Fatalf(format string, args ...interface{}) {
os.Exit(1)
}
func IsPermissionEnabled(ctx *cli.Context) bool {
if ctx.GlobalBool(EnableNodePermissionFlag.Name) {
fileName := "permission-config.json"
fullPath := filepath.Join(ctx.GlobalString(DataDirFlag.Name), fileName)
func IsPermissionEnabled(dataDir string, permissionFlag bool) bool {
if permissionFlag {
fullPath := filepath.Join(dataDir, params.PERMISSION_MODEL_CONFIG)
if _, err := os.Stat(fullPath); err != nil {
log.Warn("permission-config.json file is missing. permission service will be disabled", "err", err)
return false

View File

@ -3,4 +3,5 @@ package params
const (
PERMISSIONED_CONFIG = "permissioned-nodes.json"
BLACKLIST_CONFIG = "disallowed-nodes.json"
PERMISSION_MODEL_CONFIG = "permission-config.json"
)