Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Fixed #331 -- implemented missing chef.purge_user() and connected it to a signal. #332

Merged
merged 1 commit into from Nov 20, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions api/models.py
Expand Up @@ -15,6 +15,7 @@
from django.conf import settings
from django.contrib.auth.models import User
from django.db import models
from django.db.models.signals import post_delete
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.dispatch.dispatcher import Signal
Expand Down Expand Up @@ -818,10 +819,15 @@ def _user_publish(self):
CM.publish_user(self.flat(), self.calculate())


def _user_purge(self):
CM.purge_user(self.flat())


# attach to built-in django user
User.flat = _user_flat
User.calculate = _user_calculate
User.publish = _user_publish
User.purge = _user_purge

# define update/delete callbacks for synchronizing
# models with the configuration management backend
Expand All @@ -836,8 +842,14 @@ def _publish_user_to_cm(**kwargs):
return
kwargs['instance'].publish()


def _purge_user_from_cm(**kwargs):
kwargs['instance'].purge()


# use django signals to synchronize database updates with
# the configuration management backend
post_save.connect(_publish_to_cm, sender=App, dispatch_uid='api.models')
post_save.connect(_publish_to_cm, sender=Formation, dispatch_uid='api.models')
post_save.connect(_publish_user_to_cm, sender=User, dispatch_uid='api.models')
post_delete.connect(_purge_user_from_cm, sender=User, dispatch_uid='api.models')
11 changes: 11 additions & 0 deletions cm/chef.py
Expand Up @@ -236,6 +236,17 @@ def publish_user(user, data):
_publish('deis-users', user['username'], data)


def purge_user(user):
"""
Purge a user from configuration management.

:param app: a dict containing the username of the user
:returns: a tuple of (body, status) from the underlying HTTP response
:raises: RuntimeError
"""
_purge('deis-users', user['username'])


def publish_app(app, data):
"""
Publish an app to configuration management.
Expand Down