1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# Copyright (C) 2018 Lars Wirzenius
#
# 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 <http://www.gnu.org/licenses/>.
class EntityManager:
def __init__(self, rs, resource_type):
self._store = rs
self._type = resource_type
def list(self):
return self._store.list(self._type)
def get(self, entity_id):
return self._store.get(self._type, entity_id)
def create(self, entity_id, entity):
self._store.create(self._type, entity_id, entity)
class ApplicationManager(EntityManager):
def __init__(self, rs):
super().__init__(rs, 'application')
def get_callbacks(self, app_id):
app = self.get(app_id)
return app.get('callbacks', [])
def add_callback(self, app_id, url):
app = self.get(app_id)
app['callbacks'] = app.get('callbacks', []) + [url]
self.create(app_id, app)
|