Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
))
"""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."""
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)))
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."""