From d5c7164da81d9d72d234b8cb591f5cc2df3215fc Mon Sep 17 00:00:00 2001 From: Serghei Mihai Date: Wed, 7 Sep 2016 15:02:04 +0200 Subject: [PATCH] add corbo privisioning 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 | 37 ++++++++++++++++++++++ 5 files changed, 60 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..cad8427 --- /dev/null +++ b/hobo/agent/corbo/management/commands/hobo_notify.py @@ -0,0 +1,37 @@ +# 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) + action = notification['@type'] + data = notification['objects']['data'] + 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