Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix generating version in the current directory #5972

Merged
merged 1 commit into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions app/node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func OptionsFromRepo(r repo.Repo) ([]BuilderOpt, error) {
}

func loadPrivKeyFromKeystore(r repo.Repo) (ci.PrivKey, error) {
data, err := r.Keystore().Get("self")
data, err := r.Keystore().Get(peerPrivateKey)
if err != nil {
if err.Error() == "no key by the given name was found" {
return createPeerKey(r.Keystore())
Expand All @@ -47,23 +47,3 @@ func loadPrivKeyFromKeystore(r repo.Repo) (ci.PrivKey, error) {
}
return sk, nil
}

/*func initPeerKey(store fskeystore.Keystore, pk acrypto.PrivKey) error {
var err error
if pk == nil {
pk, _, err = acrypto.GenerateKeyPair(acrypto.RSA, defaultPeerKeyBits)
if err != nil {
return errors.Wrap(err, "failed to create peer key")
}
}

kbytes, err := acrypto.MarshalPrivateKey(pk)
if err != nil {
return err
}

if err := store.Put("self", kbytes); err != nil {
return errors.Wrap(err, "failed to store private key")
}
return nil
}*/
4 changes: 3 additions & 1 deletion app/node/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (

const defaultPeerKeyBits = 2048

const peerPrivateKey = "self"

// initCfg contains configuration for initializing a node's repo.
type initCfg struct {
initImports []*key.KeyInfo
Expand Down Expand Up @@ -71,7 +73,7 @@ func createPeerKey(store fskeystore.Keystore) (acrypto.PrivKey, error) {
return nil, err
}

if err := store.Put("self", kbytes); err != nil {
if err := store.Put(peerPrivateKey, kbytes); err != nil && !errors.Is(err, fskeystore.ErrKeyExists) {
return nil, errors.Wrap(err, "failed to store private key")
}
return pk, nil
Expand Down
9 changes: 2 additions & 7 deletions cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ var daemonCmd = &cmds.Command{
return err
}

if err = initRun(req); err != nil {
if err = initRun(req, repoDir); err != nil {
return err
}
}
Expand All @@ -121,12 +121,7 @@ var daemonCmd = &cmds.Command{
},
}

func initRun(req *cmds.Request) error {
repoDir, _ := req.Options[OptionRepoDir].(string)
err := repo.WriteVersion(repoDir, repo.LatestVersion)
if err != nil {
return err
}
func initRun(req *cmds.Request, repoDir string) error {
rep, err := getRepo(repoDir)
if err != nil {
return err
Expand Down