diff --git a/core/commands/config.go b/core/commands/config.go index b2d953f43358..c16df43b474f 100644 --- a/core/commands/config.go +++ b/core/commands/config.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "os/exec" "strings" @@ -144,48 +143,26 @@ included in the output of this command. }, Run: func(req cmds.Request, res cmds.Response) { - fname, err := config.Filename(req.InvocContext().ConfigRoot) + oConf, err := req.InvocContext().GetConfig() if err != nil { res.SetError(err, cmds.ErrNormal) return } - data, err := ioutil.ReadFile(fname) + // make copy of a current config + cMap, err := config.ToMap(oConf) if err != nil { res.SetError(err, cmds.ErrNormal) return } - - var cfg map[string]interface{} - err = json.Unmarshal(data, &cfg) + copyConfig, err := config.FromMap(cMap) if err != nil { res.SetError(err, cmds.ErrNormal) return } + copyConfig.Identity.PrivKey = "" - idmap, ok := cfg["Identity"].(map[string]interface{}) - if !ok { - res.SetError(errors.New("config has no identity"), cmds.ErrNormal) - return - } - - privKeyKey := "" // make sure we both find the name of privkey and we delete it - for key, _ := range idmap { - if strings.ToLower(key) == "privkey" { - if privKeyKey != "" { - res.SetError(errors.New("found multiple PrivKey keys"), cmds.ErrNormal) - return - } - privKeyKey = key - } - } - if privKeyKey == "" { - res.SetError(errors.New("haven't found PriveKey key"), cmds.ErrNormal) - } - - delete(idmap, privKeyKey) - - output, err := config.HumanOutput(cfg) + output, err := config.HumanOutput(copyConfig) if err != nil { res.SetError(err, cmds.ErrNormal) return