Ejemplo n.º 1
0
def create_app(secret_key, token, tracker_manager, clients_manager, notifier_manager, settings_manager,
               engine_runner, log_manager):
    AuthMiddleware.init(secret_key, token, lambda: settings_manager.get_is_authentication_enabled())
    app = create_api()
    add_static_route(app, 'webapp')
    app.add_route('/api/login', Login(settings_manager))
    app.add_route('/api/logout', Logout())
    app.add_route('/api/topics', TopicCollection(tracker_manager))
    app.add_route('/api/topics/{id}', Topic(tracker_manager))
    app.add_route('/api/topics/{id}/reset_status', TopicResetStatus(tracker_manager))
    app.add_route('/api/topics/parse', TopicParse(tracker_manager))
    app.add_route('/api/trackers', TrackerCollection(tracker_manager))
    app.add_route('/api/trackers/{tracker}', Tracker(tracker_manager))
    app.add_route('/api/trackers/{tracker}/check', TrackerCheck(tracker_manager))
    app.add_route('/api/clients', ClientCollection(clients_manager))
    app.add_route('/api/clients/{client}', Client(clients_manager))
    app.add_route('/api/clients/{client}/check', ClientCheck(clients_manager))
    app.add_route('/api/clients/{client}/default', ClientDefault(clients_manager))
    app.add_route('/api/notifiers', NotifierCollection(notifier_manager))
    app.add_route('/api/notifiers/{notifier}', Notifier(notifier_manager))
    app.add_route('/api/notifiers/{notifier}/check', NotifierCheck(notifier_manager))
    app.add_route('/api/notifiers/{notifier}/enabled', NotifierEnabled(notifier_manager))
    app.add_route('/api/settings/authentication', SettingsAuthentication(settings_manager))
    app.add_route('/api/settings/password', SettingsPassword(settings_manager))
    app.add_route('/api/settings/developer', SettingsDeveloper(settings_manager))
    app.add_route('/api/settings/logs', SettingsLogs(settings_manager))
    app.add_route('/api/settings/execute', SettingsExecute(engine_runner))
    app.add_route('/api/execute/logs', ExecuteLogs(log_manager))
    app.add_route('/api/execute/logs/{execute_id}/details', ExecuteLogsDetails(log_manager))
    app.add_route('/api/execute/logs/current', ExecuteLogCurrent(log_manager))
    app.add_route('/api/execute/call', ExecuteCall(engine_runner))
    return app
Ejemplo n.º 2
0
    def test_set_enabled_error_updating(self):
        test_notifier = NotifierCollectionTest.TestNotifier()
        # noinspection PyTypeChecker
        notifiers_manager = NotifierManager(Mock(), {'test': test_notifier})

        settings = Mock()
        test_notifier.get_settings = Mock(return_value=settings)
        type(test_notifier).is_enabled = PropertyMock(side_effect=Exception)

        notifier_enabled = NotifierEnabled(notifiers_manager)
        self.api.add_route('/api/notifiers/{notifier}/enabled', notifier_enabled)

        self.simulate_request('/api/notifiers/{0}/enabled'.format('test'), method="PUT",
                              body=json.dumps({'enabled': True}))
        self.assertEqual(self.srmock.status, falcon.HTTP_400)
Ejemplo n.º 3
0
    def test_set_enabled_invalid_key(self):
        test_notifier = NotifierCollectionTest.TestNotifier()
        # noinspection PyTypeChecker
        notifiers_manager = NotifierManager(Mock(), {'test': test_notifier})

        settings = Mock()
        test_notifier.get_settings = Mock(return_value=settings)
        test_notifier.update_settings = Mock()

        notifier_enabled = NotifierEnabled(notifiers_manager)
        self.api.add_route('/api/notifiers/{notifier}/enabled', notifier_enabled)

        self.simulate_request('/api/notifiers/{0}/enabled'.format('blabla'), method="PUT",
                              body=json.dumps({'enabled': True}))
        self.assertEqual(self.srmock.status, falcon.HTTP_404)
Ejemplo n.º 4
0
    def test_set_enabled_error_updating(self):
        test_notifier = NotifierCollectionTest.TestNotifier()
        notifiers_manager = NotifierManager({'test': test_notifier})

        settings = MagicMock()
        test_notifier.get_settings = MagicMock(return_value=settings)
        test_notifier.update_settings = MagicMock(return_value=False)

        notifier_enabled = NotifierEnabled(notifiers_manager)
        self.api.add_route('/api/notifiers/{notifier}/enabled',
                           notifier_enabled)

        body = self.simulate_request(
            '/api/notifiers/{0}/enabled'.format('test'),
            method="PUT",
            body=json.dumps({'is_enabled': True}))
        self.assertEqual(self.srmock.status, falcon.HTTP_400)