oasisprotocol / oasis-core

Performant and Confidentiality-Preserving Smart Contracts + Blockchains
https://oasisprotocol.org
Apache License 2.0
332 stars 109 forks source link

oasis-node registry entity init CLI command doesn't respect --datadir flag #3164

Open tjanez opened 4 years ago

tjanez commented 4 years ago
SUMMARY

Running oasis-node registry entity init --datadir entity/ CLI command creates a new empty entity/ directory but puts the generated files (entity_genesis.json, entity.json, entity.pem) to the current directory.

ISSUE TYPE
OASIS NODE VERSION
Software version: 20.8-git35b95b8dc
Runtime protocol version: 0.15.0
Consensus protocol version: 0.25.0
Committee protocol version: 0.10.0
Tendermint core version: 0.33.6
ABCI library version: 0.16.2
Go toolchain version: 1.14.3
STEPS TO REPRODUCE
[tadej@toronto ~]$ mkdir Temp && cd Temp
[tadej@toronto Temp]$ oasis-node-dev registry entity init --datadir entity/
ACTUAL RESULTS
[tadej@toronto Temp]$ ls -R
.:
entity  entity_genesis.json  entity.json  entity.pem

./entity:
EXPECTED RESULTS
[tadej@toronto Temp]$ ls -R
.:
entity

./entity:
entity_genesis.json  entity.json  entity.pem
kostko commented 4 years ago

May be related to the separate file signer directory?

Yawning commented 4 years ago

May be related to the separate file signer directory?

Yes.

func doInit(cmd *cobra.Command, args []string) {
    if err := cmdCommon.Init(); err != nil {
        cmdCommon.EarlyLogAndExit(err)
    }

    dataDir, err := cmdSigner.CLIDirOrPwd()
    if err != nil {
        logger.Error("failed to query data directory",
            "err", err,
        )
        os.Exit(1)
    }
// CLIDirOrPwd returns the directory with the entity files, (and the signer
// keys for file-based signer).
//
// XXX: Why this doesn't use the perfectly good datadir is beyond me.
func CLIDirOrPwd() (string, error) {
    signerDir := viper.GetString(CfgCLISignerDir)
    if signerDir == "" {
        var err error
        if signerDir, err = os.Getwd(); err != nil {
            return "", err
        }
    }
    return signerDir, nil
}
kostko commented 4 years ago

The separate file signer flag seems to be because we used to treat file signer dir = entity dir. The correct fix for this should be to introduce a flag specific to the file signer like --signer.file.path which if empty would default to the general datadir.