diff --git a/.gitlab/merge_request_templates/Default.md b/.gitlab/merge_request_templates/Default.md index 77a95da1cc40c815e4952a1283d345af56e80461..e43435cb31f415fc4f9c8447983b411627612ad7 100644 --- a/.gitlab/merge_request_templates/Default.md +++ b/.gitlab/merge_request_templates/Default.md @@ -25,6 +25,7 @@ guidelines](https://gitlab.com/caosdb/caosdb/-/blob/dev/REVIEW_GUIDELINES.md) - [ ] All automated tests pass - [ ] Reference related Issues - [ ] Up-to-date CHANGELOG.md +- [ ] Add type hints in created/changed code - [ ] Annotations in code (Gitlab comments) - Intent of new code - Problems with old code diff --git a/CHANGELOG.md b/CHANGELOG.md index 57cf7f5ee5c714500dc006ea37f7fbd5b58baff9..b590038ef3ffae1bb29b3e0fa6a9824bb25a1ecb 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/configuration.py b/src/caosdb/configuration.py index 6e8a9c6ff2083b0c30324722003fb3c08a592191..842f1ee62a5b3178b7305e4c1e0c281a2dbd3b38 100644 --- a/src/caosdb/configuration.py +++ b/src/caosdb/configuration.py @@ -51,6 +51,7 @@ def configure(inifile): def get_config(): + global _pycaosdbconf return _pycaosdbconf diff --git a/src/caosdb/utils/caosdb_admin.py b/src/caosdb/utils/caosdb_admin.py index 392d8bea2ce3d9a868c32854800ca6cb78f021ba..9c18f8962b3561999950059f23453d05edc0584d 100755 --- a/src/caosdb/utils/caosdb_admin.py +++ b/src/caosdb/utils/caosdb_admin.py @@ -116,13 +116,16 @@ 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 +139,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) @@ -301,10 +307,21 @@ USAGE # users (CRUD) subparser = subparsers.add_parser( "create_user", - help="Create a new user in caosdb's internal user database.") + help="Create a new user in caosdb's internal user database. You need " + " to activate the user before use.") subparser.set_defaults(call=do_create_user) - subparser.add_argument("-a", "--ask-password", - help="Prompt for a password.", action="store_true") + mg = subparser.add_mutually_exclusive_group() + mg.add_argument("-a", "--ask-password", + help="Prompt for a password.", action="store_true") + mg.add_argument( + "--password", + dest="user_password", + default=None, + help="Alternative way to provide the new user's password. Please " + "consider to use the more secure, interactive way (-a option).") + subparser.add_argument("-c", "--activate-user", + help="Activate the user after creation.", + action="store_true") subparser.add_argument( metavar='USERNAME', dest="user_name", @@ -331,12 +348,20 @@ 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. " + "By default, you will be prompted for the password.") 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="Alternative way to provide the user's new password. " + "The more secure (and default way) is to provide it interactively.") subparser = subparsers.add_parser( "set_user_entity",