diff --git a/CHANGELOG.md b/CHANGELOG.md index b93e013a03f5c716bad9f9337188f8715ac3c9c2..f1fab72ed234c2e94fac2ded0a0a7be6e11fca03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed ### +- It is possible now to supply a password for caosdb_admin on the command line and also activate the user directly using "-c". + ### Deprecated ### * `id_query(ids)` in apiutils diff --git a/src/caosdb/utils/caosdb_admin.py b/src/caosdb/utils/caosdb_admin.py index 392d8bea2ce3d9a868c32854800ca6cb78f021ba..d926419d984f1d83e5a111ac9d72c7c8c1c74571 100755 --- a/src/caosdb/utils/caosdb_admin.py +++ b/src/caosdb/utils/caosdb_admin.py @@ -116,13 +116,15 @@ def _promt_for_pw(): def do_create_user(args): - password = None + password = args.user_password if args.ask_password is True: password = _promt_for_pw() try: admin._insert_user(name=args.user_name, email=args.user_email, password=password) + if args.activate_user: + do_activate_user(args) except HTTPClientError as e: print(e.msg) @@ -136,7 +138,10 @@ def do_deactivate_user(args): def do_set_user_password(args): - password = _promt_for_pw() + if args.user_password is None: + password = _promt_for_pw() + else: + password = args.user_password admin._update_user(name=args.user_name, password=password) @@ -305,6 +310,8 @@ USAGE subparser.set_defaults(call=do_create_user) subparser.add_argument("-a", "--ask-password", help="Prompt for a password.", action="store_true") + subparser.add_argument("-c", "--activate-user", + help="Activate the user after creation.", action="store_true") subparser.add_argument( metavar='USERNAME', dest="user_name", @@ -314,6 +321,12 @@ USAGE nargs='?', dest="user_email", help="The email address of the new user.") + subparser.add_argument( + metavar='PASSWORD', + nargs="?", + dest="user_password", + default=None, + help="The new user's password. This is overwritten by the -a option.") subparser = subparsers.add_parser( "activate_user", help="(Re-)activate an inactive (but existing) user.") @@ -331,12 +344,18 @@ USAGE subparser = subparsers.add_parser( "set_user_password", - help="Set a new password for a user. The password is not to be given on the command line for security reasons. You will be prompted for the password.") + help="Set a new password for a user. You will be prompted for the password if PASSWORD is not given.") subparser.set_defaults(call=do_set_user_password) subparser.add_argument( metavar='USERNAME', dest="user_name", help="The name of the user who's password is to be set.") + subparser.add_argument( + metavar='PASSWORD', + nargs="?", + dest="user_password", + default=None, + help="The user's new password.") subparser = subparsers.add_parser( "set_user_entity",