How to use the defcon.status.models.Plugin.objects function in defcon

To help you get started, we’ve selected a few defcon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github criteo / defcon / defcon / status / tests.py View on Github external
def test_plugin_instance(self):
        """See if we can create plugin instances."""
        p = models.Plugin.objects.create()
        pi = models.PluginInstance.objects.create(plugin=p)
        self.assertEqual(pi.component, None)
github criteo / defcon / defcon / status / tests.py View on Github external
def test_remove_plugin(self):
        out = StringIO()
        self.addCleanup(out.close)
        management.call_command('loadplugins', stdout=out)

        with self.settings(DEFCON_PLUGINS=[]):
            management.call_command('loadplugins', stdout=out)
            self.assertIn('Removed', out.getvalue())
            self.assertEqual(0, len(models.Plugin.objects.all()))
github criteo / defcon / defcon / status / tests.py View on Github external
def test_add_plugin(self):
        out = StringIO()
        self.addCleanup(out.close)
        management.call_command('loadplugins', stdout=out)

        plugin = FakePlugin()
        self.assertIn("Created %s" % plugin.name, out.getvalue())

        plugin_model = models.Plugin.objects.get(id=plugin.short_name)
        self.assertEqual(plugin_model.id, plugin.short_name)
        self.assertEqual(plugin_model.name, plugin.name)
        self.assertEqual(plugin_model.description, plugin.description)
        self.assertEqual(plugin_model.link, plugin.link)
        self.assertEqual(plugin_model.py_module, DEFCON_PLUGINS[0])
github criteo / defcon / defcon / status / management / commands / loadcomponents.py View on Github external
def configure_plugin(self, component_obj, plugin_id,
                         name, description, config):
        """Configure a plugin for a component."""
        try:
            plugin_obj = models.Plugin.objects.get(id=plugin_id)
        except models.Plugin.DoesNotExist:
            raise base.CommandError('Plugin "%s" does not exist' % plugin_id)

        defaults = {'description': description, 'config': config}
        pinstance_obj, created = component_obj.plugins.update_or_create(
            plugin=plugin_obj, name=name, defaults=defaults)
        pinstance_obj.save()

        action = 'Created' if created else 'Updated'
        self.stdout.write(self.style.SUCCESS(
            '%s %s:%s config' % (action, component_obj.name, plugin_obj.name)))
github criteo / defcon / defcon / status / management / commands / loadplugins.py View on Github external
def handle(self, *args, **options):
        """Run the command."""
        existing_plugins = set(
            models.Plugin.objects.all().values_list('py_module', flat=True))
        updated_plugins = set()

        plugins = sorted(settings.DEFCON_PLUGINS)
        for py_module in plugins:
            self.add_plugin(py_module)
            updated_plugins.add(py_module)

        removed_plugins = existing_plugins - updated_plugins
        for py_module in removed_plugins:
            models.Plugin.objects.filter(py_module=py_module).delete()
            self.stdout.write('Removed %s' % py_module)
github iksaif / my-little-ticket / my_little_ticket / tickets / management / commands / loadplugins.py View on Github external
def handle(self, *args, **options):
        """Run the command."""
        existing_plugins = set(
            models.Plugin.objects.all().values_list("py_module", flat=True)
        )
        updated_plugins = set()

        plugins = sorted(settings.DEFCON_PLUGINS)
        for py_module in plugins:
            self.add_plugin(py_module)
            updated_plugins.add(py_module)

        removed_plugins = existing_plugins - updated_plugins
        for py_module in removed_plugins:
            models.Plugin.objects.filter(py_module=py_module).delete()
            self.stdout.write("Removed %s" % py_module)
github iksaif / my-little-ticket / my_little_ticket / tickets / management / commands / loadplugins.py View on Github external
def add_plugin(self, py_module):
        """Add a plugin."""
        plugin_class = module_loading.import_string(py_module)
        plugin = plugin_class()

        defaults = {
            "id": plugin.short_name,
            "name": plugin.name,
            "description": plugin.description,
            "link": plugin.link,
            "py_module": py_module,
        }
        plugin_obj, created = models.Plugin.objects.update_or_create(
            py_module=py_module, defaults=defaults
        )

        action = "Created" if created else "Updated"
        self.stdout.write(
            self.style.SUCCESS(
                "%s %s:%s config" % (action, plugin_obj.name, plugin_obj.py_module)
            )
github criteo / defcon / defcon / status / views.py View on Github external
queryset = models.Component.objects.all()
    serializer_class = serializers.ComponentSimpleSerializer


class ComponentViewSet(viewsets.ModelViewSet):
    """API view for Component."""

    queryset = models.Component.objects.all()
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
    serializer_class = serializers.ComponentSerializer


class PluginViewSet(viewsets.ModelViewSet):
    """API view for Plugin."""

    queryset = models.Plugin.objects.all()
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
    serializer_class = serializers.PluginSerializer


class PluginInstanceViewSet(viewsets.ModelViewSet):
    """API view for PluginInstance."""

    queryset = models.PluginInstance.objects.all()
    permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
    serializer_class = serializers.PluginInstanceSerializer


class StatusViewSet(viewsets.ModelViewSet):
    """API view for Status."""

    queryset = models.Status.objects.all()
github criteo / defcon / defcon / status / management / commands / loadplugins.py View on Github external
def handle(self, *args, **options):
        """Run the command."""
        existing_plugins = set(
            models.Plugin.objects.all().values_list('py_module', flat=True))
        updated_plugins = set()

        plugins = sorted(settings.DEFCON_PLUGINS)
        for py_module in plugins:
            self.add_plugin(py_module)
            updated_plugins.add(py_module)

        removed_plugins = existing_plugins - updated_plugins
        for py_module in removed_plugins:
            models.Plugin.objects.filter(py_module=py_module).delete()
            self.stdout.write('Removed %s' % py_module)
github iksaif / my-little-ticket / my_little_ticket / tickets / management / commands / loadplugins.py View on Github external
def handle(self, *args, **options):
        """Run the command."""
        existing_plugins = set(
            models.Plugin.objects.all().values_list("py_module", flat=True)
        )
        updated_plugins = set()

        plugins = sorted(settings.DEFCON_PLUGINS)
        for py_module in plugins:
            self.add_plugin(py_module)
            updated_plugins.add(py_module)

        removed_plugins = existing_plugins - updated_plugins
        for py_module in removed_plugins:
            models.Plugin.objects.filter(py_module=py_module).delete()
            self.stdout.write("Removed %s" % py_module)