-
Notifications
You must be signed in to change notification settings - Fork 90
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
cmd: add gen-p2pkey command #316
Conversation
@@ -29,7 +29,7 @@ jobs: | |||
tags: "${{ steps.get-version.outputs.version }}" | |||
|
|||
- name: Generate cli reference | |||
run: docker run ghcr.io/obolnetwork/charon/charon:${{steps.get-version.outputs.version}} charon --help > cli-reference.txt | |||
run: docker run ghcr.io/obolnetwork/charon/charon:${{steps.get-version.outputs.version}} charon run --help > cli-reference.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not related, but I saw that cli-reference created for the release is incorrect.
Codecov Report
@@ Coverage Diff @@
## main #316 +/- ##
=======================================
Coverage ? 55.12%
=======================================
Files ? 59
Lines ? 4747
Branches ? 0
=======================================
Hits ? 2617
Misses ? 1779
Partials ? 351
Continue to review full report at Codecov.
|
dir := "testdata/simnet" | ||
require.NoError(t, os.RemoveAll(dir)) | ||
err := os.MkdirAll(dir, 0o755) | ||
dir, err := os.MkdirTemp("", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixing this test that was flapping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
cmd/cmd.go
Outdated
@@ -41,6 +41,7 @@ func New() *cobra.Command { | |||
return newRootCmd( | |||
newVersionCmd(runVersionCmd), | |||
newEnrCmd(runNewENR), | |||
newGenP2PCmd(runGenP2P), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we name it to newGenP2PKeyCmd to be more specific?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool
cmd/genp2p.go
Outdated
"github.com/obolnetwork/charon/p2p" | ||
) | ||
|
||
func newGenP2PCmd(runFunc func(io.Writer, p2p.Config, string) error) *cobra.Command { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: name as newGenP2PKeyCmd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool
cmd/genp2p.go
Outdated
} | ||
|
||
// runGenP2P stores a new p2pkey to disk and prints the ENR for the provided config. | ||
func runGenP2P(w io.Writer, config p2p.Config, dataDir string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: runGenP2PKey
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool
func newSavedPrivKey(keyPath string) (*ecdsa.PrivateKey, error) { | ||
if err := os.MkdirAll(filepath.Dir(keyPath), 0o755); err != nil { | ||
// NewSavedPrivKey generates a new ecdsa k1 key and saves it to the directory. | ||
func NewSavedPrivKey(datadir string) (*ecdsa.PrivateKey, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe name as NewP2PKey or NewPrivKey ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NewP2PKey
would stutter since the package already p2p
. and NewPrivKey
doesn't indicate that the key is also saved to disk.
652fd27
to
9a41fef
Compare
func runNewENR(w io.Writer, config p2p.Config, dataDir string) error { | ||
identityKey, loaded, err := p2p.LoadOrCreatePrivKey(dataDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#893 was fixed here
Makes loading vs creating p2pkeys explicit both when running charon and as commands.
category: feature
ticket: #315