Projet

Général

Profil

0001-add-corbo-privisioning-agent-12910.patch

Serghei Mihai, 10 mars 2017 17:09

Télécharger (4,43 ko)

Voir les différences:

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 | 40 ++++++++++++++++++++++
 5 files changed, 63 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
hobo/agent/corbo/__init__.py
1
default_app_config = 'hobo.agent.corbo.apps.CorboAgentConfig'
hobo/agent/corbo/apps.py
1
# hobo - portal to configure and deploy applications
2
# Copyright (C) 2015  Entr'ouvert
3
#
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU Affero General Public License as published
6
# by the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU Affero General Public License for more details.
13
#
14
# You should have received a copy of the GNU Affero General Public License
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16

  
17
from django.apps import AppConfig
18

  
19
class CorboAgentConfig(AppConfig):
20
    name = 'hobo.agent.corbo'
21
    label = 'corbo_agent'
22
    verbose_name = 'Corbo Agent'
hobo/agent/corbo/management/commands/hobo_notify.py
1
# hobo - portal to configure and deploy applications
2
# Copyright (C) 2015  Entr'ouvert
3
#
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU Affero General Public License as published
6
# by the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU Affero General Public License for more details.
13
#
14
# You should have received a copy of the GNU Affero General Public License
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16

  
17
from django.db.transaction import atomic
18

  
19
from hobo.agent.common.management.commands.hobo_notify import Command as CommonCommand
20

  
21
from corbo.models import Subscription
22

  
23
class Command(CommonCommand):
24

  
25
    @classmethod
26
    def process_notification(cls, tenant, notification):
27
        super(CommonCommand, self).process_notification(cls, tenant, notification)
28
        action = notification['@type']
29
        data = notification['objects']['data']
30
        for o in data:
31
            for s in Subscription.objects.filter(uuid=o['uuid']):
32
                with atomic():
33
                    if action == 'provision':
34
                        if s.identifier.startswith('mailto:'):
35
                            s.identifier = 'mailto:%s' % o['email']
36
                        elif s.identifier.startswith('sms:'):
37
                            s.identifier = 'sms:%s' % o['mobile']
38
                        s.save()
39
                    elif action == 'deprovision':
40
                        s.delete()
0
-