Show user
This commit is contained in:
parent
d6f48e4861
commit
a5bb63fb14
|
@ -19,6 +19,8 @@ ldap:
|
|||
username: cn=root,dc=unit,dc=macaomilano,dc=org
|
||||
password: root
|
||||
|
||||
base_dn: dc=unit,dc=macaomilano,dc=org
|
||||
|
||||
|
||||
logging:
|
||||
version: 1
|
||||
|
|
30
src/phicli
30
src/phicli
|
@ -7,27 +7,43 @@ import phi.ldap.client
|
|||
from phi.config import get_config
|
||||
from phi.logging import setup_logging, get_logger
|
||||
|
||||
from phi.ldap.user import get_user_by_uid
|
||||
|
||||
log = get_logger(__name__)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
parser.add_argument('--config', metavar='config.yml',
|
||||
type=str, help='custom configuration file')
|
||||
parser.add_argument(
|
||||
'--config', metavar='config.yml', help='custom configuration file')
|
||||
|
||||
ns = parser.parse_args(sys.argv[1:])
|
||||
config_file = ns.config
|
||||
subparses = parser.add_subparsers(title='actions', dest='action')
|
||||
|
||||
parser_showuser = subparses.add_parser(
|
||||
'showuser', help='display user fields')
|
||||
parser_showuser.add_argument(dest='uid', help='user identifier')
|
||||
|
||||
namespace = parser.parse_args(sys.argv[1:])
|
||||
config_file = namespace.config
|
||||
|
||||
config_file, config = get_config(config_file)
|
||||
setup_logging(config.get('logging', {}))
|
||||
log.info("Using configuration at '{}':\n".format(config_file))
|
||||
log.info("Using configuration at '{}':\n{}"
|
||||
.format(config_file, pp(config)))
|
||||
|
||||
# TODO: check fields in config
|
||||
client = phi.ldap.client.Client(**config['ldap'])
|
||||
|
||||
log.info('Opening LDAP client')
|
||||
client = phi.ldap.client.Client(**config['ldap'])
|
||||
client.open()
|
||||
|
||||
#
|
||||
log.info('Arguments: {}'.format(pp(namespace.__dict__)))
|
||||
|
||||
if namespace.action == 'showuser':
|
||||
uid = namespace.uid
|
||||
user = get_user_by_uid(client, uid)
|
||||
print('\nuid: {}\n{}\n\n'.format(uid, pp(user)))
|
||||
|
||||
log.info('Closing LDAP client')
|
||||
client.close()
|
||||
|
|
Loading…
Reference in New Issue
Block a user