-
Notifications
You must be signed in to change notification settings - Fork 35.6k
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
contrib: rpcauth.py - Add new option (-json) to output text in json format #29433
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. |
Missing |
Concept ACK |
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.
Concept ACk
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.
ACK for 713ab48. Cool feature. Inline comments provided.
share/rpcauth/rpcauth.py
Outdated
@@ -24,6 +25,7 @@ def main(): | |||
parser = ArgumentParser(description='Create login credentials for a JSON-RPC user') | |||
parser.add_argument('username', help='the username for authentication') | |||
parser.add_argument('password', help='leave empty to generate a random password or specify "-" to prompt for password', nargs='?') | |||
parser.add_argument("-json", help="output to json instead of plain-text", action='store_true') |
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.
The share/rpcauth/README.md
file should also be updated to explain the argument and capability change in rpcauth.py
.
nit:
Recommend making the argument be a single letter (e.g. -j
for json) to follow the existing style with -h
for help and prevent conflation with -j -s -o -n
.
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.
thank you. yes single "-" makes more sense.
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.
ACK for 713ab48
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.
Here's an example for the README.md:
diff --git a/share/rpcauth/README.md b/share/rpcauth/README.md
index 6b5e4446a5..1b3acb1dac 100644
--- a/share/rpcauth/README.md
+++ b/share/rpcauth/README.md
@@ -15,5 +15,5 @@ positional arguments:
optional arguments:
-h, --help show this help message and exit
- -j, -json output data in json format
+ -j, --json output data in json format
Not sure it makes sense to do this. If you're parsing JSON, surely you can do the trivial things inside rpcauth yourself? |
Probably also true, my Bitcoin node setup script currently just does something like: python3 "$SCRIPT_DIR/rpcauth.py" \
"$bitcoin_rpcuser" "$bitcoin_rpcpassword" | grep rpcauth >> /etc/bitcoin/bitcoin.conf |
The default behavior is the same, so no change unless someone specifically wants json output. For anyone just outputting "rpcauth=XXXXX" directly into bitcoin.conf, yes the grep solution is fine. But if, in addition to that, you wanted to extract the value of rpcauth, then its more steps. (further, this assumes "=" will always be the delimiter) By providing a machine-friendly output format that makes such deployments less fragile in the future. |
Are you still working on this? #29433 (comment) |
Apologies for delay - PR now has changed prefix / title. I also included update to README.md to document change. |
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.
Seems fine to add this.
Please squash your commits according to https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits once they are ready for review. Also, the |
Thanks for the walk-thru.....I followed the steps so hopefully all is ok... |
review ACK 4f74671 |
Are you still working on this? |
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.
Concept ACK.
Looks like these commits (4f74671, 1606590, and f2fb13b) should be squashed to clean up and tell a concise story of update.
Seems to work well:
$ ./rpcauth.py
usage: rpcauth.py [-h] [-j] username [password]
rpcauth.py: error: the following arguments are required: username
$ ./rpcauth.py -h
usage: rpcauth.py [-h] [-j] username [password]
Create login credentials for a JSON-RPC user
positional arguments:
username the username for authentication
password leave empty to generate a random password or specify "-" to prompt for password
options:
-h, --help show this help message and exit
-j, --json output to json instead of plain-text
$ ./rpcauth.py tester1
String to be appended to bitcoin.conf:
rpcauth=tester1:5be9e5538a73ee796d73c16fe7267343$fb3462c51b9a943a5235eea45311100e637c47ef76e2ce00bd109d21940e231c
Your password:
j70a0dzR8gEZfdU3Su1c9jZi6k107iAMKiMdchHhrQE
$ ./rpcauth.py -j tester2
{"username": "tester2", "password": "NymKCrxvVxWvDd3XwPUaqgZp9Wr5cf3Kg6Flvss2b_U", "rpcauth": "tester2:7e1296561e4830d9987d38b32b2daf1d$d30aac9fd97726f9dcf6015508b01ec5ad9d1fd7055e9b61d619578b2bb871f5"}
$ ./rpcauth.py --json tester3
{"username": "tester3", "password": "kjhzSg-2jtizz4Krjj1KmQxrY0Vemf0jI3og2MTHFVs", "rpcauth": "tester3:f7a9248c1b11fec9efa1c681c42a9209$c68a4465920456f3cd99b322b58dbed50b9d4643cb13ce61228c9b8343a65bde"}
$ ./rpcauth.py --json tester4 throwawaypass
{"username": "tester4", "password": "throwawaypass", "rpcauth": "tester4:09156b6ab4a6ae5ab11508c4a6f5f68b$8804e2f73c22bac9532e40b3c6cdb2c61668bad9a4d7c67f4284bdcffb9bedc1"}
$ ./rpcauth.py tester5 anotherthrowaypass
String to be appended to bitcoin.conf:
rpcauth=tester5:563ad3d4b62f746c689f3853b0147ebe$7cf8ca75dd3f3623d79f2e5eeca6a69eefdd61b8d1546cba571ed6385ebc8dad
Your password:
anotherthrowaypass
Please squash your commits according to https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits |
…on format -j/--json update and remove un-needed parens Update README to reflect new -j/--json options
Thanks for your help @maflcko, I squashed and hope that it looks ok now. |
ACK 9adf949 |
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.
tACK 9adf949
Makes sense to me to be able to output this in JSON for automated setups.
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.
Thanks for squashing commits.
ACK for 9adf949
ACK 9adf949 |
fa3e115 doc: Correct pull request prefix for scripts and tools (MarcoFalke) Pull request description: `script` is confusing, because in the context of Bitcoin, it usually means Bitcoin script (c.f. `CScript` in `script.h`, or pull requests such as #27122 using the prefix). This could be fixed by renaming it to `scripts` (with a plural `s` at the end), however, looking at the current usage `contrib` and `cli` seem more common (#29687, #26953, #26584, #24864, #30074, #29433 ...) ACKs for top commit: fanquake: ACK fa3e115 willcl-ark: ACK fa3e115 hebasto: ACK fa3e115. theuni: ACK fa3e115 Tree-SHA512: fb3a3892ca5f859e590c8a620350c397ef1f9eafd9e174c70ef50095d401a396758d6c93ad41888da8025c41e25e691f30c18f9e974af13597f2266bb2c53b6d
This is a simple change to rpcauth.py utility in order to output as json instead raw text.
This is beneficial because integrating json output is simpler with multiple different forms of automation and tooling