Commit 6a17098f authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Add deletion of user at rabbitmq

parent 5abcfb5f
...@@ -4,7 +4,7 @@ from django.conf import settings ...@@ -4,7 +4,7 @@ from django.conf import settings
from django.dispatch import receiver, Signal from django.dispatch import receiver, Signal
from django.utils.timezone import make_aware from django.utils.timezone import make_aware
from rest_framework.authtoken.models import Token from rest_framework.authtoken.models import Token
from django.db.models.signals import post_save from django.db.models.signals import post_save, pre_delete
# from django.db.models.signals import m2m_changed # from django.db.models.signals import m2m_changed
from datetime import datetime from datetime import datetime
...@@ -103,6 +103,13 @@ def register_at_rabbitmq( ...@@ -103,6 +103,13 @@ def register_at_rabbitmq(
RabbitMQInstance().register_site(instance) RabbitMQInstance().register_site(instance)
@receiver(pre_delete, sender=Site)
def deregister_at_rabbitmq(
sender, instance=None, **kwargs):
RabbitMQInstance().deregister_site(instance)
class Service(models.Model): class Service(models.Model):
name = models.CharField(max_length=150, unique=True) name = models.CharField(max_length=150, unique=True)
description = models.TextField(max_length=300, blank=True) description = models.TextField(max_length=300, blank=True)
......
...@@ -14,6 +14,9 @@ class RabbitMQInstance: ...@@ -14,6 +14,9 @@ class RabbitMQInstance:
# guest only works on the localhost # guest only works on the localhost
self.auth = HTTPBasicAuth('guest', 'guest') self.auth = HTTPBasicAuth('guest', 'guest')
def get_uri(self, path):
return '{}/{}'.format(self.api, path)
def set_topic_permissions(self, site): def set_topic_permissions(self, site):
username = site.client.username username = site.client.username
set_topic_permission_uri = '{}/topic-permissions/{}/{}/'.format( set_topic_permission_uri = '{}/topic-permissions/{}/{}/'.format(
...@@ -89,12 +92,7 @@ class RabbitMQInstance: ...@@ -89,12 +92,7 @@ class RabbitMQInstance:
# delete user at the rabbitmq instance # delete user at the rabbitmq instance
def delete_user(self, site): def delete_user(self, site):
username = site.client.username username = site.client.username
user_creation_uri = '{}/users/{}/'.format( user_creation_uri = self.get_uri('users/{}/'.format(username))
self.api,
username
)
print('registerring client {}'.format(site.client.username))
user_creation_data = { user_creation_data = {
'password': str(site.client.auth_token.key), 'password': str(site.client.auth_token.key),
...@@ -103,9 +101,12 @@ class RabbitMQInstance: ...@@ -103,9 +101,12 @@ class RabbitMQInstance:
# TODO might fail # TODO might fail
r = requests.delete( r = requests.delete(
user_creation_uri, json=user_creation_data, auth=self.auth) user_creation_uri, json=user_creation_data, auth=self.auth)
print('RabbitMQ: create_user {}'.format(r.status_code)) print('RabbitMQ: delete_user {}'.format(r.status_code))
def register_site(self, site): def register_site(self, site):
self.create_user(site) self.create_user(site)
self.set_permissions(site) self.set_permissions(site)
self.set_topic_permissions(site) self.set_topic_permissions(site)
def deregister_site(self, site):
self.delete_user(site)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment