diff options
author | bstin <barry.github@capsmx.com> | 2024-02-14 06:20:32 -0600 |
---|---|---|
committer | b0xxer <barry@a9.local> | 2024-04-25 08:32:28 -0500 |
commit | 9adf949d2aa6d199b85295b18c08967395b5570a (patch) | |
tree | fe3b4f775cd2bf3665b8f0f4bde3358100cf7f51 /share | |
parent | baed5edeb611d949982c849461949c645f8998a7 (diff) |
contrib: rpcauth.py - Add new option (-j/--json) to output text in json format
-j/--json update and remove un-needed parens
Update README to reflect new -j/--json options
Diffstat (limited to 'share')
-rw-r--r-- | share/rpcauth/README.md | 1 | ||||
-rwxr-xr-x | share/rpcauth/rpcauth.py | 12 |
2 files changed, 10 insertions, 3 deletions
diff --git a/share/rpcauth/README.md b/share/rpcauth/README.md index 6f627b867b..1b3acb1dac 100644 --- a/share/rpcauth/README.md +++ b/share/rpcauth/README.md @@ -15,4 +15,5 @@ positional arguments: optional arguments: -h, --help show this help message and exit + -j, --json output data in json format ``` diff --git a/share/rpcauth/rpcauth.py b/share/rpcauth/rpcauth.py index cc7bba1f8b..506fcf9d91 100755 --- a/share/rpcauth/rpcauth.py +++ b/share/rpcauth/rpcauth.py @@ -7,6 +7,7 @@ from argparse import ArgumentParser from getpass import getpass from secrets import token_hex, token_urlsafe import hmac +import json def generate_salt(size): """Create size byte hex salt""" @@ -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("-j", "--json", help="output to json instead of plain-text", action='store_true') args = parser.parse_args() if not args.password: @@ -35,9 +37,13 @@ def main(): salt = generate_salt(16) password_hmac = password_to_hmac(salt, args.password) - print('String to be appended to bitcoin.conf:') - print(f'rpcauth={args.username}:{salt}${password_hmac}') - print(f'Your password:\n{args.password}') + if args.json: + odict={'username':args.username, 'password':args.password, 'rpcauth':f'{args.username}:{salt}${password_hmac}'} + print(json.dumps(odict)) + else: + print('String to be appended to bitcoin.conf:') + print(f'rpcauth={args.username}:{salt}${password_hmac}') + print(f'Your password:\n{args.password}') if __name__ == '__main__': main() |