Commit 91c1aaa1 authored by Adin Schmahmann's avatar Adin Schmahmann

fix: do not create and print out an unused new peerID when initializing from a config

parent af089dee
......@@ -250,14 +250,20 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
}
}
identity, err := config.CreateIdentity(os.Stdout, []options.KeyGenerateOption{
options.Key.Type(algorithmDefault),
})
if err != nil {
return err
if conf == nil {
identity, err := config.CreateIdentity(os.Stdout, []options.KeyGenerateOption{
options.Key.Type(algorithmDefault),
})
if err != nil {
return err
}
conf, err = config.InitWithIdentity(identity)
if err != nil {
return err
}
}
if err = doInit(os.Stdout, cctx.ConfigRoot, false, &identity, profiles, conf); err != nil {
if err = doInit(os.Stdout, cctx.ConfigRoot, false, profiles, conf); err != nil {
return err
}
}
......
......@@ -113,24 +113,30 @@ environment variable:
}
}
var err error
var identity config.Identity
if nBitsGiven {
identity, err = config.CreateIdentity(os.Stdout, []options.KeyGenerateOption{
options.Key.Size(nBitsForKeypair),
options.Key.Type(algorithm),
})
} else {
identity, err = config.CreateIdentity(os.Stdout, []options.KeyGenerateOption{
options.Key.Type(algorithm),
})
}
if err != nil {
return err
if conf == nil {
var err error
var identity config.Identity
if nBitsGiven {
identity, err = config.CreateIdentity(os.Stdout, []options.KeyGenerateOption{
options.Key.Size(nBitsForKeypair),
options.Key.Type(algorithm),
})
} else {
identity, err = config.CreateIdentity(os.Stdout, []options.KeyGenerateOption{
options.Key.Type(algorithm),
})
}
if err != nil {
return err
}
conf, err = config.InitWithIdentity(identity)
if err != nil {
return err
}
}
profiles, _ := req.Options[profileOptionName].(string)
return doInit(os.Stdout, cctx.ConfigRoot, empty, &identity, profiles, conf)
return doInit(os.Stdout, cctx.ConfigRoot, empty, profiles, conf)
},
}
......@@ -152,7 +158,7 @@ func applyProfiles(conf *config.Config, profiles string) error {
return nil
}
func doInit(out io.Writer, repoRoot string, empty bool, identity *config.Identity, confProfiles string, conf *config.Config) error {
func doInit(out io.Writer, repoRoot string, empty bool, confProfiles string, conf *config.Config) error {
if _, err := fmt.Fprintf(out, "initializing IPFS node at %s\n", repoRoot); err != nil {
return err
}
......@@ -165,18 +171,6 @@ func doInit(out io.Writer, repoRoot string, empty bool, identity *config.Identit
return errRepoExists
}
if identity == nil {
return fmt.Errorf("No Identity provided for initialization")
}
if conf == nil {
var err error
conf, err = config.InitWithIdentity(*identity)
if err != nil {
return err
}
}
if err := applyProfiles(conf, confProfiles); err != nil {
return err
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment