How to use the defcon.status.models.Component.objects.all 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_remove_component(self):
        out = StringIO()
        self.addCleanup(out.close)
        components = copy.deepcopy(DEFCON_COMPONENTS)

        with self.settings(DEFCON_COMPONENTS=components):
            management.call_command("loadcomponents", stdout=out)

        with self.settings(DEFCON_COMPONENTS={}):
            management.call_command("loadcomponents", stdout=out)
            self.assertIn('Removed production', out.getvalue())
            self.assertEqual(0, len(models.Component.objects.all()))
github criteo / defcon / defcon / status / management / commands / loadcomponents.py View on Github external
def handle(self, *args, **options):
        """Run the command."""
        existing_components = set(
            models.Component.objects.all().values_list('id', flat=True))
        updated_components = set()

        components = sorted(settings.DEFCON_COMPONENTS.items())
        for cid, component in components:
            self.add_component(cid, component)
            updated_components.add(cid)

        removed_components = existing_components - updated_components
        for cid in removed_components:
            models.Component.objects.filter(id=cid).delete()
            self.stdout.write('Removed %s' % cid)
github criteo / defcon / defcon / status / management / commands / runplugins.py View on Github external
def handle(self, *args, **options):
        """Run the command."""
        # TODO: add filters by components and plugins.

        # Get the status that haven't expired yet to make them expire if
        # they disappeared.
        now = timezone.now()
        existing_statuses = set(models.Status.objects.filter(
            time_end__gte=now).values_list('id', flat=True))
        updated_statuses = set()

        for component_obj in models.Component.objects.all():
            for plugin_obj in component_obj.plugins.all():
                updated_statuses |= self.run_plugin(component_obj, plugin_obj)

        expired_statuses = (existing_statuses - updated_statuses)
        if expired_statuses:
            self.stdout.write(self.style.SUCCESS('Expiring %s' % expired_statuses))
            models.Status.objects.filter(id__in=expired_statuses).update(time_end=now)
github criteo / defcon / defcon / status / views.py View on Github external
"""Views of defcon.status."""
from django import shortcuts

from annoying import decorators as an_decorators
from rest_framework import viewsets
from rest_framework import permissions

from defcon.status import models
from defcon.status import serializers


class DefConViewSet(viewsets.ReadOnlyModelViewSet):
    """API view for Component with expanded statuses."""

    queryset = models.Component.objects.all()
    serializer_class = serializers.ComponentFullSerializer


class SimpleViewSet(viewsets.ReadOnlyModelViewSet):
    """API view for Component with expanded statuses."""

    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
github criteo / defcon / defcon / status / views.py View on Github external
def index(request):
    """Show the list of components."""
    components = models.Component.objects.all()
    return {'components': components}