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

contrib: rpcauth.py - Add new option (-json) to output text in json format #29433

Merged
merged 1 commit into from
Apr 25, 2024

Conversation

bstin
Copy link
Contributor

@bstin bstin commented Feb 14, 2024

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

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 14, 2024

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK maflcko, willcl-ark, tdb3, achow101
Concept ACK kristapsk

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

@maflcko
Copy link
Member

maflcko commented Feb 14, 2024

Missing contrib: prefix in pull title? Also, the title should explain the change, both for the pull, as well as the commit title.

@kristapsk
Copy link
Contributor

Concept ACK

Copy link
Contributor

@BrandonOdiwuor BrandonOdiwuor left a comment

Choose a reason for hiding this comment

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

Concept ACk

Copy link
Contributor

@tdb3 tdb3 left a 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.

@@ -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')
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

ACK for 713ab48

Copy link
Contributor

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

@luke-jr
Copy link
Member

luke-jr commented Feb 20, 2024

Not sure it makes sense to do this. If you're parsing JSON, surely you can do the trivial things inside rpcauth yourself?

@kristapsk
Copy link
Contributor

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

@bstin
Copy link
Contributor Author

bstin commented Feb 20, 2024

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.

@maflcko
Copy link
Member

maflcko commented Feb 21, 2024

Are you still working on this? #29433 (comment)

@bstin bstin changed the title Update rpcauth.py rpcauth.py - Add new option (-json) to output text in json format Feb 21, 2024
@bstin
Copy link
Contributor Author

bstin commented Feb 21, 2024

Apologies for delay - PR now has changed prefix / title. I also included update to README.md to document change.

Copy link
Member

@maflcko maflcko left a 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.

share/rpcauth/rpcauth.py Outdated Show resolved Hide resolved
@maflcko
Copy link
Member

maflcko commented Feb 22, 2024

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 contrib: prefix is still missing.

@bstin bstin changed the title rpcauth.py - Add new option (-json) to output text in json format contrib: rpcauth.py - Add new option (-json) to output text in json format Feb 22, 2024
@bstin
Copy link
Contributor Author

bstin commented Feb 22, 2024

Thanks for the walk-thru.....I followed the steps so hopefully all is ok...

@maflcko
Copy link
Member

maflcko commented Feb 22, 2024

review ACK 4f74671

@DrahtBot DrahtBot requested a review from tdb3 February 22, 2024 19:19
share/rpcauth/README.md Outdated Show resolved Hide resolved
@DrahtBot DrahtBot requested review from kristapsk and tdb3 and removed request for tdb3 and kristapsk February 22, 2024 20:02
@maflcko
Copy link
Member

maflcko commented Apr 23, 2024

Are you still working on this?

Copy link
Contributor

@tdb3 tdb3 left a 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

@maflcko
Copy link
Member

maflcko commented Apr 24, 2024

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
@bstin
Copy link
Contributor Author

bstin commented Apr 25, 2024

Thanks for your help @maflcko, I squashed and hope that it looks ok now.

@maflcko
Copy link
Member

maflcko commented Apr 25, 2024

ACK 9adf949

@DrahtBot DrahtBot requested a review from tdb3 April 25, 2024 14:13
Copy link
Member

@willcl-ark willcl-ark left a 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.

Copy link
Contributor

@tdb3 tdb3 left a 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

@achow101
Copy link
Member

ACK 9adf949

@achow101 achow101 merged commit 2066295 into bitcoin:master Apr 25, 2024
9 of 13 checks passed
fanquake added a commit that referenced this pull request May 22, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants