From 26238223b1ba161c3040569bc91e2370d3b95c4d Mon Sep 17 00:00:00 2001 From: Serghei Mihai Date: Wed, 7 Sep 2016 15:02:04 +0200 Subject: [PATCH] add corbo privisionning agent (#12910) --- hobo/agent/corbo/__init__.py | 1 + hobo/agent/corbo/apps.py | 22 +++++++++++ hobo/agent/corbo/management/__init__.py | 0 hobo/agent/corbo/management/commands/__init__.py | 0 .../agent/corbo/management/commands/hobo_notify.py | 46 ++++++++++++++++++++++ 5 files changed, 69 insertions(+) create mode 100644 hobo/agent/corbo/__init__.py create mode 100644 hobo/agent/corbo/apps.py create mode 100644 hobo/agent/corbo/management/__init__.py create mode 100644 hobo/agent/corbo/management/commands/__init__.py create mode 100644 hobo/agent/corbo/management/commands/hobo_notify.py diff --git a/hobo/agent/corbo/__init__.py b/hobo/agent/corbo/__init__.py new file mode 100644 index 0000000..e92ee7c --- /dev/null +++ b/hobo/agent/corbo/__init__.py @@ -0,0 +1 @@ +default_app_config = 'hobo.agent.corbo.apps.CorboAgentConfig' diff --git a/hobo/agent/corbo/apps.py b/hobo/agent/corbo/apps.py new file mode 100644 index 0000000..727b002 --- /dev/null +++ b/hobo/agent/corbo/apps.py @@ -0,0 +1,22 @@ +# hobo - portal to configure and deploy applications +# Copyright (C) 2015 Entr'ouvert +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from django.apps import AppConfig + +class CorboAgentConfig(AppConfig): + name = 'hobo.agent.corbo' + label = 'corbo_agent' + verbose_name = 'Corbo Agent' diff --git a/hobo/agent/corbo/management/__init__.py b/hobo/agent/corbo/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hobo/agent/corbo/management/commands/__init__.py b/hobo/agent/corbo/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hobo/agent/corbo/management/commands/hobo_notify.py b/hobo/agent/corbo/management/commands/hobo_notify.py new file mode 100644 index 0000000..de9ec75 --- /dev/null +++ b/hobo/agent/corbo/management/commands/hobo_notify.py @@ -0,0 +1,46 @@ +# hobo - portal to configure and deploy applications +# Copyright (C) 2015 Entr'ouvert +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from hobo.agent.common.management.commands.hobo_notify import Command as CommonCommand + +from corbo.models import Subscription + +class Command(CommonCommand): + + @classmethod + def process_notification(cls, tenant, notification): + super(CommonCommand, self).process_notification(cls, tenant, notification) + object_type = notification['objects']['@type'] + full = notification['full'] if 'full' in notification else False + if object_type != 'user': + return + data = notification['objects']['data'] + action = notification['@type'] + if full: + uuids = [obj['uuid'] for obj in data] + Subscription.objects.exclude(uuid__in=uuids).delete() + return + + for obj in data: + for subscription in Subscription.objects.filter(uuid=obj['uuid']): + if action == 'provision': + if subscription.identifier.startswith('mailto:'): + subscription.identifier = 'mailto:%s' % obj['email'] + elif subscription.identifier.startswith('sms:'): + subscription.identifier = 'sms:%s' % obj['mobile'] + subscription.save() + elif action == 'deprovision': + subscription.delete() -- 2.11.0