Show user

This commit is contained in:
uid 2020-10-10 23:27:08 +02:00
parent d6f48e4861
commit a5bb63fb14
2 changed files with 25 additions and 7 deletions

View File

@ -19,6 +19,8 @@ ldap:
username: cn=root,dc=unit,dc=macaomilano,dc=org username: cn=root,dc=unit,dc=macaomilano,dc=org
password: root password: root
base_dn: dc=unit,dc=macaomilano,dc=org
logging: logging:
version: 1 version: 1

View File

@ -7,27 +7,43 @@ import phi.ldap.client
from phi.config import get_config from phi.config import get_config
from phi.logging import setup_logging, get_logger from phi.logging import setup_logging, get_logger
from phi.ldap.user import get_user_by_uid
log = get_logger(__name__) log = get_logger(__name__)
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--config', metavar='config.yml', parser.add_argument(
type=str, help='custom configuration file') '--config', metavar='config.yml', help='custom configuration file')
ns = parser.parse_args(sys.argv[1:]) subparses = parser.add_subparsers(title='actions', dest='action')
config_file = ns.config
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) config_file, config = get_config(config_file)
setup_logging(config.get('logging', {})) 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') log.info('Opening LDAP client')
client = phi.ldap.client.Client(**config['ldap'])
client.open() 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') log.info('Closing LDAP client')
client.close() client.close()