How to use the defcon.status.models.Plugin 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 / 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 / admin.py View on Github external
"""Admin classes for defcon.status."""
from django.contrib import admin
from defcon.status import models


@admin.register(models.Component)
class ComponentAdmin(admin.ModelAdmin):
    """Admin for Component."""

    list_display = ('name', 'link', 'contact')


@admin.register(models.Plugin)
class PluginAdmin(admin.ModelAdmin):
    """Admin for Plugin."""

    list_display = ('name', 'link')


@admin.register(models.PluginInstance)
class PluginInstanceAdmin(admin.ModelAdmin):
    """Admin for PluginInstance."""

    list_display = ('name', 'plugin', 'component', 'created_on', 'modified_on')


@admin.register(models.Status)
class StatusAdmin(admin.ModelAdmin):
    """Admin for Status."""
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 / serializers.py View on Github external
class ComponentSimpleSerializer(ComponentSerializer):
    """Serializer for Component."""

    class Meta(ComponentSerializer.Meta):
        """Configuration."""

        fields = ['name', 'contact', 'link', 'defcon', 'description']


class PluginSerializer(serializers.HyperlinkedModelSerializer):
    """Serializer for Plugin."""

    class Meta:
        """Configuration."""

        model = models.Plugin
        fields = '__all__'


class PluginInstanceSerializer(serializers.HyperlinkedModelSerializer):
    """Serializer for PluginInstance."""

    class Meta:
        """Configuration."""

        model = models.PluginInstance
        fields = '__all__'


class StatusSerializer(serializers.HyperlinkedModelSerializer):
    """Serializer for Status."""