[jira] [Commented] (AIRFLOW-3051) The cli tools for manipulating users should be symmetric with connections

2018-09-24 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/AIRFLOW-3051?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16626766#comment-16626766
 ] 

ASF GitHub Bot commented on AIRFLOW-3051:
-

r39132 closed pull request #3936: [AIRFLOW-3051] Change CLI to make users ops 
similar to connections
URL: https://github.com/apache/incubator-airflow/pull/3936
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/bin/cli.py b/airflow/bin/cli.py
index dbab8b38d8..1c5494ead1 100644
--- a/airflow/bin/cli.py
+++ b/airflow/bin/cli.py
@@ -1347,74 +1347,75 @@ def kerberos(args):  # noqa
 
 
 @cli_utils.action_logging
-def create_user(args):
-fields = {
-'role': args.role,
-'username': args.username,
-'email': args.email,
-'firstname': args.firstname,
-'lastname': args.lastname,
-}
-empty_fields = [k for k, v in fields.items() if not v]
-if empty_fields:
-raise SystemExit('Required arguments are missing: {}.'.format(
-', '.join(empty_fields)))
-
-appbuilder = cached_appbuilder()
-role = appbuilder.sm.find_role(args.role)
-if not role:
-raise SystemExit('{} is not a valid role.'.format(args.role))
-
-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:')
-if password != password_confirmation:
-raise SystemExit('Passwords did not match!')
+def users(args):
+if args.list:
+
+appbuilder = cached_appbuilder()
+users = appbuilder.sm.get_all_users()
+fields = ['id', 'username', 'email', 'first_name', 'last_name', 
'roles']
+users = [[user.__getattribute__(field) for field in fields] for user 
in users]
+msg = tabulate(users, [field.capitalize().replace('_', ' ') for field 
in fields],
+   tablefmt="fancy_grid")
+if sys.version_info[0] < 3:
+msg = msg.encode('utf-8')
+print(msg)
 
-if appbuilder.sm.find_user(args.username):
-print('{} already exist in the db'.format(args.username))
 return
-user = appbuilder.sm.add_user(args.username, args.firstname, args.lastname,
-  args.email, role, password)
-if user:
-print('{} user {} created.'.format(args.role, args.username))
-else:
-raise SystemExit('Failed to create user.')
 
+if args.create:
+fields = {
+'role': args.role,
+'username': args.username,
+'email': args.email,
+'firstname': args.firstname,
+'lastname': args.lastname,
+}
+empty_fields = [k for k, v in fields.items() if not v]
+if empty_fields:
+raise SystemExit('Required arguments are missing: {}.'.format(
+', '.join(empty_fields)))
 
-@cli_utils.action_logging
-def delete_user(args):
-if not args.username:
-raise SystemExit('Required arguments are missing: username')
+appbuilder = cached_appbuilder()
+role = appbuilder.sm.find_role(args.role)
+if not role:
+raise SystemExit('{} is not a valid role.'.format(args.role))
+
+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:')
+if password != password_confirmation:
+raise SystemExit('Passwords did not match!')
 
-appbuilder = cached_appbuilder()
+if appbuilder.sm.find_user(args.username):
+print('{} already exist in the db'.format(args.username))
+return
+user = appbuilder.sm.add_user(args.username, args.firstname, 
args.lastname,
+  args.email, role, password)
+if user:
+print('{} user {} created.'.format(args.role, args.username))
+else:
+raise SystemExit('Failed to create user.')
 
-try:
-u = next(u for u in appbuilder.sm.get_all_users() if u.username == 
args.username)
-except StopIteration:
-raise SystemExit('{} is not a valid user.'.format(args.username))
+if args.delete:
+if not args.username:
+raise SystemExit('Required arguments are missing: username')
 
-if appbuilder.sm.del_register_user(u):
-

[jira] [Commented] (AIRFLOW-3051) The cli tools for manipulating users should be symmetric with connections

2018-09-22 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/AIRFLOW-3051?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16624859#comment-16624859
 ] 

ASF GitHub Bot commented on AIRFLOW-3051:
-

kaxil opened a new pull request #3936: [AIRFLOW-3051] Change CLI to make users 
ops similar to connections
URL: https://github.com/apache/incubator-airflow/pull/3936
 
 
   
   
   Make sure you have checked _all_ steps below.
   
   ### Jira
   
   - [x] My PR addresses the following [Airflow 
Jira](https://issues.apache.org/jira/browse/AIRFLOW/) issues and references 
them in the PR title. For example, "\[AIRFLOW-XXX\] My Airflow PR"
 - https://issues.apache.org/jira/browse/AIRFLOW-3051
   
   
   ### Description
   
   - [x] Here are some details about my PR, including screenshots of any UI 
changes:
   The ability to manipulate users from the  command line is a bit clunky.  
Currently 'airflow create_user' and 'airflow delete_user' and 'airflow 
list_users'.  It seems that these ought to be made more like connections, so 
that it becomes 'airflow users list ...', 'airflow users delete ...' and 
'airflow users create ...'
   
   ### Tests
   
   - [x] My PR adds the following unit tests __OR__ does not need testing for 
this extremely good reason:
   Manipulated tests
   
   ### Commits
   
   - [x] My commits all reference Jira issues in their subject lines, and I 
have squashed multiple commits if they address the same issue. In addition, my 
commits follow the guidelines from "[How to write a good git commit 
message](http://chris.beams.io/posts/git-commit/)":
 1. Subject is separated from body by a blank line
 1. Subject is limited to 50 characters (not including Jira issue reference)
 1. Subject does not end with a period
 1. Subject uses the imperative mood ("add", not "adding")
 1. Body wraps at 72 characters
 1. Body explains "what" and "why", not "how"
   
   ### Documentation
   
   - [x] In case of new functionality, my PR adds documentation that describes 
how to use it.
 - When adding new operators/hooks/sensors, the autoclass documentation 
generation needs to be added.
   
   ### Code Quality
   
   - [x] Passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> The cli tools for manipulating users should be symmetric with connections
> -
>
> Key: AIRFLOW-3051
> URL: https://issues.apache.org/jira/browse/AIRFLOW-3051
> Project: Apache Airflow
>  Issue Type: Wish
>Affects Versions: 1.10.0
>Reporter: William Pursell
>Priority: Major
>
> The ability to manipulate users from the  command line is a bit clunky.  
> Currently 'airflow create_user' and 'airflow delete_user' and 'airflow 
> list_users'.  It seems that these ought to be made more like connections, so 
> that it becomes 'airflow users list ...', 'airflow users delete ...' and 
> 'airflow users create ...'



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)