# 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 . 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 delete(self, entity_id): return self._store.delete(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)