def config(): '''Display the LDAP configuration''' header('Current configuration') for key in sorted(manager.config): if key.startswith('LDAP_'): echo(b'{key}: {value}'.format(key=white(key), value=safe_unicode(manager.config[key])))
def check(): '''Check the LDAP configuration''' bind_dn = manager.config.get('LDAP_BIND_USER_DN', None) if not bind_dn: exit_with_error('Missing LDAP_BIND_USER_DN setting') header('Trying to connect with bind user') try: who_am_i = manager.connection.extend.standard.who_am_i() success('Bind DN successfully connected') echo('Bind DN user is "{}"'.format(white(safe_unicode(who_am_i)))) except Exception as e: exit_with_error('Unable to connect', e) header('Trying to authenticate an user') email = prompt(white('User email')) password = prompt(white('User password'), hide_input=True) result = manager.authenticate(email, password) if result.status == AuthenticationResponseStatus.success: success('User successfully connected') echo('Authenticated user is "{email} ({dn})"'.format( email=white(safe_unicode(result.user_id)), dn=white(safe_unicode(result.user_dn)) )) echo('User has the following remote attributes:') for key, value in result.user_info.items(): echo(b'{key}: {value}'.format(key=white(safe_unicode(key)), value=safe_unicode(value))) echo('Local user will be created with the following values:') for key, value in manager.extract_user_infos(result.user_info).items(): echo(b'{key}: {value}'.format(key=white(safe_unicode(key)), value=safe_unicode(value))) else: exit_with_error('Unable to authenticate user "{0}"'.format(safe_unicode(email))) success('LDAP configuration is working')
def render(): '''Force (re)rendering stored images''' from udata.core.organization.models import Organization from udata.core.post.models import Post from udata.core.reuse.models import Reuse from udata.core.user.models import User header('Rendering images') count = Counter() total = Counter() organizations = Organization.objects(logo__exists=True) total['orgs'] = organizations.count() log.info('Processing {0} organizations logos'.format(total['orgs'])) for org in organizations: count['orgs'] += render_or_skip(org, 'logo') users = User.objects(avatar__exists=True) total['users'] = users.count() log.info('Processing {0} user avatars'.format(total['users'])) for user in users: count['users'] += render_or_skip(user, 'avatar') posts = Post.objects(image__exists=True) total['posts'] = posts.count() log.info('Processing {0} post images'.format(total['posts'])) for post in posts: count['posts'] += render_or_skip(post, 'image') reuses = Reuse.objects(image__exists=True) total['reuses'] = reuses.count() log.info('Processing {0} reuse images'.format(total['reuses'])) for reuse in reuses: count['reuses'] += render_or_skip(reuse, 'image') log.info('''Summary: Organization logos: {count[orgs]}/{total[orgs]} User avatars: {count[users]}/{total[users]} Post images: {count[posts]}/{total[posts]} Reuse images: {count[reuses]}/{total[reuses]} '''.format(count=count, total=total)) success('Images rendered')