2020-10-10 18:45:16 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
from pprint import pformat as pp
|
|
|
|
|
|
|
|
from phi.config import get_config
|
|
|
|
from phi.logging import setup_logging, get_logger
|
2020-10-11 11:55:36 +02:00
|
|
|
from phi import cli
|
|
|
|
import phi.ldap.client
|
2020-10-10 23:27:08 +02:00
|
|
|
from phi.ldap.user import get_user_by_uid
|
|
|
|
|
2020-10-10 18:45:16 +02:00
|
|
|
log = get_logger(__name__)
|
|
|
|
|
2020-10-11 01:11:56 +02:00
|
|
|
|
2020-10-11 11:55:36 +02:00
|
|
|
@cli.register('dispaly user field', ['user identifier'])
|
2020-10-11 01:11:56 +02:00
|
|
|
def showuser(uid):
|
|
|
|
user = get_user_by_uid(client, uid)
|
|
|
|
print('\nuid: {}\n{}\n\n'.format(uid, pp(user)))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-10-11 11:55:36 +02:00
|
|
|
cli.add_arg('--config', 'config.yml', 'custom configuration file')
|
|
|
|
args = cli.get_args()
|
2020-10-11 01:11:56 +02:00
|
|
|
|
|
|
|
config_file = args['config']
|
2020-10-10 18:45:16 +02:00
|
|
|
|
2020-10-10 21:14:21 +02:00
|
|
|
config_file, config = get_config(config_file)
|
|
|
|
setup_logging(config.get('logging', {}))
|
2020-10-10 23:27:08 +02:00
|
|
|
log.info("Using configuration at '{}':\n{}"
|
|
|
|
.format(config_file, pp(config)))
|
2020-10-10 18:45:16 +02:00
|
|
|
|
2020-10-10 23:27:08 +02:00
|
|
|
# TODO: check fields in config
|
2020-10-10 18:45:16 +02:00
|
|
|
client = phi.ldap.client.Client(**config['ldap'])
|
2020-10-10 23:27:08 +02:00
|
|
|
|
|
|
|
log.info('Opening LDAP client')
|
2020-10-10 18:45:16 +02:00
|
|
|
client.open()
|
|
|
|
|
2020-10-11 01:11:56 +02:00
|
|
|
log.info('Arguments: {}'.format(pp(args)))
|
2020-10-10 23:27:08 +02:00
|
|
|
|
2020-10-11 11:55:36 +02:00
|
|
|
cli.run(args)
|
2020-10-10 18:45:16 +02:00
|
|
|
|
|
|
|
log.info('Closing LDAP client')
|
|
|
|
client.close()
|