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

Load config from well-known locations + add init command for initializing config #582

Merged
merged 40 commits into from
Mar 12, 2024

Conversation

QuinnWilton
Copy link
Contributor

Description

This adds the start of an init command for configuring Homestar from the CLI. When run interactively, it currently provides a wizard for configuring the keys used by homestar, however it can also be run non-interactively using values configured through CLI flags.

It also includes allowances for outputting a generated configuration over stdout, and the start of some patterns for handling some common CLI knobs, like --no-input, --quiet, and --force, though these are only likely to see more use as we expose more configuration options to this interactive wizard.

There's still a lot of polish that can be done around how we handle error reporting and interrupts, like control+c, during interactive usage, but this is a start that should make it a lot easier to begin expanding the configuration options we expose to the user.

Link to issue

Please add a link to any relevant issues/tickets.

Screenshots/Screencaps

image
image
image
image
image

@QuinnWilton QuinnWilton requested a review from a team as a code owner February 21, 2024 01:05
homestar-runtime/Cargo.toml Outdated Show resolved Hide resolved
homestar-runtime/src/main.rs Outdated Show resolved Hide resolved
homestar-runtime/src/cli/init.rs Outdated Show resolved Hide resolved
homestar-runtime/Cargo.toml Outdated Show resolved Hide resolved
@QuinnWilton
Copy link
Contributor Author

I pushed up some small tweaks, including converting InquireError to a miette report, so that we're able to cleanup the error reporting on a SIGINT received during prompting. Here's how that looks now:

image

Exceptional errors still currently panic, which I think is possibly the right call for now, until we do the work of translating those into a miette error that directs users to file an issue in the repo or something.

Copy link

codecov bot commented Feb 21, 2024

Codecov Report

Attention: Patch coverage is 65.33742% with 113 lines in your changes are missing coverage. Please review.

Project coverage is 69.05%. Comparing base (90c6246) to head (9c8b07a).
Report is 6 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #582      +/-   ##
==========================================
- Coverage   69.17%   69.05%   -0.12%     
==========================================
  Files          95       98       +3     
  Lines       12953    13491     +538     
==========================================
+ Hits         8960     9316     +356     
- Misses       3993     4175     +182     
Files Coverage Δ
homestar-runtime/src/main.rs 77.14% <100.00%> (+0.67%) ⬆️
homestar-runtime/src/settings/libp2p_config.rs 100.00% <100.00%> (ø)
homestar-runtime/src/settings.rs 98.45% <98.11%> (+0.27%) ⬆️
homestar-runtime/src/cli.rs 58.66% <0.00%> (-4.20%) ⬇️
homestar-runtime/src/settings/pubkey_config.rs 75.60% <76.66%> (+3.47%) ⬆️
homestar-runtime/src/cli/init.rs 56.89% <56.89%> (ø)

... and 5 files with indirect coverage changes

Copy link
Contributor

@bgins bgins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on this! Looks great ✨

@zeeshanlakhani
Copy link
Contributor

@QuinnWilton could we add some integration/CLI (no runtime needed) tests to have tests around the functionality here?

Copy link
Contributor

@zeeshanlakhani zeeshanlakhani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments thus far.

  • Q: Shouldn't we also have the option to generate a PEM/DER file for users (not just provide your own) as another option? Essentially, replace the OpenSSL genkey we've/users have been doing manually? I thought this was one goal of the work?

❤️ the experience btw.

homestar-runtime/Cargo.toml Outdated Show resolved Hide resolved
homestar-runtime/Cargo.toml Outdated Show resolved Hide resolved
homestar-runtime/src/cli/init.rs Outdated Show resolved Hide resolved
homestar-runtime/src/cli/init.rs Outdated Show resolved Hide resolved
homestar-runtime/src/cli/init.rs Show resolved Hide resolved
homestar-runtime/src/settings.rs Outdated Show resolved Hide resolved
homestar-runtime/src/cli/init.rs Show resolved Hide resolved
homestar-runtime/src/cli/init.rs Outdated Show resolved Hide resolved
@QuinnWilton
Copy link
Contributor Author

Added some comments thus far.

  • Q: Shouldn't we also have the option to generate a PEM/DER file for users (not just provide your own) as another option? Essentially, replace the OpenSSL genkey we've/users have been doing manually? I thought this was one goal of the work?

❤️ the experience btw.

I don't see any APIs exposed by the libp2p-identity crate for encoding keys as PEM/DER files. Are you aware of anything that I may have missed? Or were you imagining that we'd pull in another crypto crate / shell out to OpenSSL for that?

Either way, I just pushed up fixes for all of your other comments.

For windows: $USERPROFILE/.config/homestar/settings.toml
For macos + linux: $XDG_CONFIG_HOME/homestar/settings.toml
               or: $HOME/.config/homestar/settings.toml
The comments erroneously listed only ed25519 as an allowed public
key type, however secp256k1 keys are also supported.
This skips writing the newly generated configuration file to disk,
and instead outputs it over stdout
This is in preparation for including richer forms of interactivity
around options like keypair generation and management.
This suppresses all auxiliary output, like that intended for humans,
to aid in non-interactive use from a script.
This runs the command in non-interactive mode, by disabling all
prompts, and instead erroring if interactive inpupt is required.
Even though Inquire will already error if we attempt to prompt
for input without being attached to a TTY, explicitly running
the command in non-interactive mode will ensure that our error
messaging will be consistent whether or not a TTY is available
@QuinnWilton
Copy link
Contributor Author

@zeeshanlakhani I just pushed up PEM generation for ed25519, improved PEM parsing for ed25519, and the tests you requested! Headed to dinner now, but merge conflicts are fixed and I'll check CI in the morning 😊

PubkeyConfig::GenerateFromSeed(RNGSeed::new(key_type, seed.0))
}
PubkeyConfigOption::FromFile => {
// HACK: We need to manually instantiate the struct with a custom formatter,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure we need to call this a hack vs constraints on the type/impls?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess my other Q is if we had to use PathBuf, but I'm guessing yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't necessarily need PathBuf, but my original reasoning was:

  1. Supporting non-UTF-8 paths
  2. Hooking into Inquire's error handling flow, for handling parse errors by displaying an error and re-prompting the user

(1) may not apply because we still construct the PathBuf by going through the parser closure, which is over a &str, and so will only contain UTF-8 codepoints anyway.

(2) also doesn't look important, because it seems like the FromStr impl for PathBuf is Infallible, so we shouldn't need to worry about error handling there.

Want me to rip this out and just return the input as a String?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@QuinnWilton yeah, seeing your responses, I think we can rip this out easily and go with String.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I'll do that, thanks!

@zeeshanlakhani
Copy link
Contributor

zeeshanlakhani commented Mar 6, 2024

@QuinnWilton Code is looking pretty good, but there was a new setting added in main that's missing here after rebase: enable_resolve_receipts_in_background. Once that's updated, I'll do a run-through and check the DX experience.

@bgins
Copy link
Contributor

bgins commented Mar 7, 2024

Hey @QuinnWilton! Trying out the new PEM key file features. They work great, and I love them. ❤️

I have a couple of minor DX requests:

  • Could we update the help text to indicate that the --key-file flag will generate a key if an existing key does not exist at the path?
  • When generating a key file with the --key-file flag and selecting the Secp256k1 option, an unsupported error is thrown (as expected) but an empty key file is created. Could we clean up and remove the key file in this error case?

@QuinnWilton
Copy link
Contributor Author

Hey @QuinnWilton! Trying out the new PEM key file features. They work great, and I love them. ❤️

I have a couple of minor DX requests:

  • Could we update the help text to indicate that the --key-file flag will generate a key if an existing key does not exist at the path?
  • When generating a key file with the --key-file flag and selecting the Secp256k1 option, an unsupported error is thrown (as expected) but an empty key file is created. Could we clean up and remove the key file in this error case?

Just pushed up these two changes; thanks!

@zeeshanlakhani
Copy link
Contributor

@QuinnWilton last minor thing:

  • Could we generate the pem in the config directory by default if no file is given to key-file and override the default path if run again?

Copy link
Contributor

@zeeshanlakhani zeeshanlakhani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@QuinnWilton left a few last small changes/details. Great work.

homestar-runtime/src/cli.rs Outdated Show resolved Hide resolved
homestar-runtime/src/cli/init.rs Show resolved Hide resolved
@QuinnWilton QuinnWilton merged commit fc1f4e7 into main Mar 12, 2024
33 checks passed
@QuinnWilton QuinnWilton deleted the quinn/config branch March 12, 2024 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants