-
Notifications
You must be signed in to change notification settings - Fork 95
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
Parse .cookie, .env, or environment variables for RPC auth details #87
Conversation
Thanks for looking into this! I think having the option to read the credentials from environment variables is nice, but we still should be able to give them explicitly, if they are not set via the environment variables. Moreover, probably even more useful that allowing to read a
|
My bad, forgot to add that explicitly specifying the credentials still works, just added it to the PR description. And that makes sense about using the For getting the |
c467680
to
7c3cb6c
Compare
Had a bunch of small things to fix and didn't realize force push would make a record of each update and clutter up the log heh... sorry to anyone if you got a bunch of unnecessary emails/notifications because of this. Anyway, I've now added functionality to parse the I've tested this on MacOS and Linux. I'm not sure how it holds up on Windows, and I don't have a Windows machine on hand. If anyone is able to test on Windows that'd be greatly appreciated, otherwise in the meantime I may investigate ways to do it remotely or maybe using docker. |
10564e3
to
834c790
Compare
f60cc4f
to
8604cb0
Compare
Nice one, @alecchendev! Reading the
That's not a problem! Usually we will just add fixup commits during review to address comments and then squash them later before merge.
Yeah, Windows is definitely the odd one out here so testing would be nice! I'm in the same boat with no access to Windows. |
Thanks for the feedback @dunxen!
Ah, makes sense!
I'll try and see what I can do about this today and try to leave instructions for any reviewers to reproduce if I figure it out. |
b4a71aa
to
d840d19
Compare
Great stuff! I'll take another look at this PR for anything else. This will probably only merge after the holidays I imagine. |
Okay I tested on Windows and made some changes so it works now. Not really sure how else to show some sort of proof so here are some screenshots: Testing on WindowsResultsWithout any rpc auth provided (error message, note the correct windows filepath): With bitcoind running (works as it should): How to reproduceI was hoping my testing would be more easily reproducible maybe using docker but didn't get that working, and seemed to be a lot more work than I thought. Instead I spun up a windows EC2 instance on AWS and connected to it using remote desktop:
|
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.
Wow, this is really awesome work! I think it looks basically good to go as-is, with one note, Given we're adding so much contents here IMO it'd be nice to move the existing parse_startup_args
and the new code to a new file.
Also sorry for the delay in getting back over the holidays here. |
Thanks! I was thinking |
Awesome, thanks. Can you squash this down into one or five logically-distinct commits that don't undo or fixup changes in previous commits? https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits is a good reference if you need it. |
Yes! |
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.
This is awesome work, thanks. I'm gonna go ahead and merge with the two trivial nits here, but would appreciate a followup to fix the testnet path, at least.
}; | ||
|
||
let data_dir_path_with_net = match network { | ||
Some(Network::Testnet) => data_dir_path.join("testnet"), |
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.
IIRC this should be testnet3
let (bitcoind_rpc_username, bitcoind_rpc_password) = if bitcoind_rpc_info_parts.len() == 1 { | ||
get_rpc_auth_from_cookie(None, Some(network), None) | ||
.or(get_rpc_auth_from_env_file(None)) | ||
.or(get_rpc_auth_from_env_vars()) |
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: generally env vars should override cookie auth, though I'm not opinionated about env file preference.
Will do! Will probably get to it sometime in the next couple of days. |
Implements #49
Summary of changes
.cookie
,.env
or environment variablesget_cookie_path
,get_rpc_auth_from_cookie
,get_rpc_auth_from_env_vars
,get_rpc_auth_from_env_file
andparse_env_file
parse_rpc_auth
print_rpc_auth_help
to communicate to the user how they can specify credentials in these new waysTests: Wasn't sure what the best way to test was; mainly added unit tests for new functions.
Output
These are some of my results from running the sample command for different scenarios:
Explicitly specifying credentials in command (current functionality):
Without
.cookie
,.env
file or environment variables (should error):With
.cookie
in defaultdatadir
location for bitcoind:With
.env
file:With environment variables
Possible next steps
I mentioned it in the issue but I'm fairly new to both Rust and contributing to open-source so please let me know if I can do anything better!