import logging from django.http import HttpResponse from django.contrib.auth import authenticate LOGGER = logging.getLogger(__name__) def user_endpoint(request): LOGGER.debug('RabbitMQ sent auth request') if 'username' in request.POST and 'password' in request.POST: username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user: LOGGER.info('Authenticated client as %s', user) if user.is_superuser: return HttpResponse("allow administrator") else: return HttpResponse("allow management") LOGGER.error('Failed to authenticate user for RabbitMQ') return HttpResponse("deny") def vhost(request): return HttpResponse("allow") def resource(request): return HttpResponse("allow") def topic(request): return HttpResponse("allow")