From e90b31ee41d0b395d594ac8be5a78ef1ab29342b Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Tue, 29 Sep 2015 19:39:30 +0200 Subject: [PATCH 1/4] agent/common: prepare for user provisionning (#8440) We factorize the processing of notifications between a part agnostic to the type objects and another which is specific, here process_notification() and provision_role(). --- .../common/management/commands/hobo_notify.py | 29 +++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/hobo/agent/common/management/commands/hobo_notify.py b/hobo/agent/common/management/commands/hobo_notify.py index 22e6e00..cf996b2 100644 --- a/hobo/agent/common/management/commands/hobo_notify.py +++ b/hobo/agent/common/management/commands/hobo_notify.py @@ -59,19 +59,9 @@ class Command(BaseCommand): and 'description' in o @classmethod - def process_notification(cls, tenant, notification): - assert cls.check_valid_notification(notification), \ - 'invalid notification' - service = tenant.get_service() - action = notification['@type'] - audience = notification['audience'] - full = notification['full'] if 'full' in notification else False - entity_id = service.get('saml-sp-metadata-url') - assert entity_id, 'service has no saml-sp-metadat-url field' - if entity_id not in audience: - return + def provision_role(cls, action, data, full=False): uuids = set() - for o in notification['objects']: + for o in data: assert cls.check_valid_role(o) uuids.add(o['uuid']) if action == 'provision': @@ -95,3 +85,18 @@ class Command(BaseCommand): elif action == 'deprovision': for role in Role.objects.filter(uuid__in=uuids): role.delete() + + @classmethod + def process_notification(cls, tenant, notification): + assert cls.check_valid_notification(notification), \ + 'invalid notification' + service = tenant.get_service() + action = notification['@type'] + audience = notification['audience'] + full = notification['full'] if 'full' in notification else False + entity_id = service.get('saml-sp-metadata-url') + assert entity_id, 'service has no saml-sp-metadat-url field' + if entity_id not in audience: + return + uuids = set() + cls.provision_role(action, notification['objects'], full=full) -- 2.1.4