Change get-group-users to a simpler implementation

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Joseph Nuthalapati 2018-07-03 12:47:40 +05:30 committed by James Valleroy
parent 1a095564b0
commit a50b40ee56
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 19 additions and 17 deletions

View File

@ -86,10 +86,12 @@ def parse_arguments():
subparser.add_argument('groupname',
help='LDAP group to remove the user from')
help_get_admin_user = 'Get the list of all users in an LDAP group'
subparser = subparsers.add_parser('get-group-users', help=help_get_admin_user)
subparser.add_argument('groupname', help='name of the LDAP group to get the '
'list of users')
help_get_group_users = 'Get the list of all users in an LDAP group'
subparser = subparsers.add_parser('get-group-users',
help=help_get_group_users)
subparser.add_argument(
'groupname', help='name of the LDAP group to get the '
'list of users')
subparsers.required = True
return parser.parse_args()
@ -351,13 +353,14 @@ def subcommand_remove_user_from_group(arguments):
def subcommand_get_group_users(arguments):
""" Get the list of admin users """
process = _run(['ldapgid', arguments.groupname], stdout=subprocess.PIPE)
output = str(process.stdout).split()
users_info = output[1].split('=')[1].strip('\\n').split(',')
for user_info in users_info:
user_name = user_info.split('(')[1].split(')')[0]
print(user_name)
""" Get the list of users of an LDAP group."""
process = _run(['ldapgid', '-P', arguments.groupname],
stdout=subprocess.PIPE)
output = process.stdout.decode()
users = output.rsplit(':')[-1]
if users:
for user in users.strip().split(','):
print(user)
def flush_cache():

View File

@ -111,9 +111,8 @@ def get_last_admin_user():
""" Check if there is only one admin user
if yes return its name else return None
"""
admin_users = actions.superuser_run('users',
['get-group-users','admin']
).strip().split('\n')
if len(admin_users) > 1:
return None
return admin_users[0]
admin_users = actions.superuser_run(
'users', ['get-group-users', 'admin']).strip().split('\n')
if len(admin_users) == 1:
return admin_users[0]
return None