feat: add node config generator - #144
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements the “node.yaml generator” from #51 by introducing a new nylon init CLI command that generates a node config (including a freshly generated private key) and prints the corresponding public key for use in central.yaml. It also tightens key deserialization by validating decoded key lengths and updates the Getting Started guide to use the new workflow.
Changes:
- Add
nylon initcommand to generatenode.yamlwith secure file permissions and optional network/DNS/distribution/hook settings. - Reject invalid private/public keys during YAML/text deserialization by enforcing expected decoded byte length.
- Update documentation and add tests covering init behavior and key-length validation.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| state/serialize.go | Adds decoded-length validation for private/public key text deserialization. |
| state/serialize_test.go | Adds regression tests ensuring wrong-length keys are rejected. |
| docs/guides/getting-started.mdx | Updates onboarding to use nylon init to generate node.yaml and keypair output guidance. |
| cmd/init.go | Implements the new init command and node-config construction/validation logic. |
| cmd/init_test.go | Adds tests for config generation, overwrite protection, dist option completeness, and validation errors. |
Comments suppressed due to low confidence (2)
cmd/init.go:116
- For better UX and consistency with other commands (e.g.,
sealtrims key files), trim whitespace from--keybefore base64-decoding. This makesnylon init --key "$(cat keyfile)"/ copy-paste less error-prone.
if opts.key != "" {
if err := privateKey.UnmarshalText([]byte(opts.key)); err != nil {
return nil, fmt.Errorf("invalid private key: %w", err)
}
}
cmd/init.go:148
- Trim whitespace from
--dist-keybefore decoding so distribution bootstrap works reliably when users copy values from files/docs.
var key state.NyPublicKey
if err := key.UnmarshalText([]byte(opts.distKey)); err != nil {
return nil, fmt.Errorf("invalid distribution key: %w", err)
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| ```bash | ||
| nylon key | ||
| nylon init --id node-1 |
There was a problem hiding this comment.
Perhaps we should use sudo here, so that the file is only readable by root
There was a problem hiding this comment.
I was thinking of going more in the direction of using this to generate a config file and the user can just copy it to the right (root owned) location.
| postDown []string | ||
| } | ||
|
|
||
| func newInitCmd() *cobra.Command { |
There was a problem hiding this comment.
I think what might be easier for the end user is to have an interactive CLI which asks the user for these flags. (We can still have the flags just for easy automation)
There was a problem hiding this comment.
Sure, I can add such a flow.
5fbc1bc to
6b22140
Compare
This addresses #51 and adds an init command as discussed in the issue