Repository: incubator-airflow Updated Branches: refs/heads/v1-10-test a05a72eee -> 5495d2590
[AIRFLOW-2409] Supply password as a parameter Supply the password as a parameter on the cli Closes #3304 from Fokko/supply-password (cherry picked from commit 2a079b953fe35049805079684fe43a1499694e4b) Signed-off-by: Fokko Driesprong <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/5495d259 Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/5495d259 Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/5495d259 Branch: refs/heads/v1-10-test Commit: 5495d2590d976613308dde90872de0282c64a088 Parents: a05a72e Author: Fokko Driesprong <[email protected]> Authored: Thu May 3 08:32:51 2018 +0200 Committer: Fokko Driesprong <[email protected]> Committed: Thu May 3 08:33:14 2018 +0200 ---------------------------------------------------------------------- airflow/bin/cli.py | 8 +++++++- tests/core.py | 15 +++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/5495d259/airflow/bin/cli.py ---------------------------------------------------------------------- diff --git a/airflow/bin/cli.py b/airflow/bin/cli.py index f26cbe4..3097dce 100644 --- a/airflow/bin/cli.py +++ b/airflow/bin/cli.py @@ -1221,6 +1221,8 @@ def create_user(args): if args.use_random_password: password = ''.join(random.choice(string.printable) for _ in range(16)) + elif args.password: + password = args.password else: password = getpass.getpass('Password:') password_confirmation = getpass.getpass('Repeat for confirmation:') @@ -1622,6 +1624,10 @@ class CLIFactory(object): ('-u', '--username',), help='Username of the user', type=str), + 'password': Arg( + ('-p', '--password',), + help='Password of the user', + type=str), 'use_random_password': Arg( ('--use_random_password',), help='Do not prompt for password. Use random string instead', @@ -1768,7 +1774,7 @@ class CLIFactory(object): 'func': create_user, 'help': "Create an admin account", 'args': ('role', 'username', 'email', 'firstname', 'lastname', - 'use_random_password'), + 'password', 'use_random_password'), }, ) subparsers_dict = {sp['func'].__name__: sp for sp in subparsers} http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/5495d259/tests/core.py ---------------------------------------------------------------------- diff --git a/tests/core.py b/tests/core.py index 6d18ffe..4cece16 100644 --- a/tests/core.py +++ b/tests/core.py @@ -7,9 +7,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -983,13 +983,20 @@ class CliTests(unittest.TestCase): args = self.parser.parse_args(['list_dags', '--report']) cli.list_dags(args) - def test_cli_create_user(self): + def test_cli_create_user_random_password(self): args = self.parser.parse_args([ - 'create_user', '-u', 'test', '-l', 'doe', '-f', 'jon', + 'create_user', '-u', 'test1', '-l', 'doe', '-f', 'jon', '-e', '[email protected]', '-r', 'Viewer', '--use_random_password' ]) cli.create_user(args) + def test_cli_create_user_supplied_password(self): + args = self.parser.parse_args([ + 'create_user', '-u', 'test2', '-l', 'doe', '-f', 'jon', + '-e', '[email protected]', '-r', 'Viewer', '-p', 'test' + ]) + cli.create_user(args) + def test_cli_list_tasks(self): for dag_id in self.dagbag.dags.keys(): args = self.parser.parse_args(['list_tasks', dag_id])
