2022-11-08 09:54:51 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
|
|
|
|
from rest_framework import mixins
|
|
|
|
|
|
|
|
from common.utils import get_object_or_none
|
|
|
|
from orgs.mixins.api import OrgBulkModelViewSet, OrgGenericViewSet
|
|
|
|
|
|
|
|
from assets.models import ChangeSecretAutomation, ChangeSecretRecord, AutomationExecution
|
|
|
|
from assets import serializers
|
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
'ChangeSecretAutomationViewSet', 'ChangeSecretRecordViewSet'
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class ChangeSecretAutomationViewSet(OrgBulkModelViewSet):
|
|
|
|
model = ChangeSecretAutomation
|
|
|
|
filter_fields = ('name', 'secret_type', 'secret_strategy')
|
|
|
|
search_fields = filter_fields
|
|
|
|
ordering_fields = ('name',)
|
|
|
|
serializer_class = serializers.ChangeSecretAutomationSerializer
|
|
|
|
|
|
|
|
|
|
|
|
class ChangeSecretRecordViewSet(mixins.ListModelMixin, OrgGenericViewSet):
|
|
|
|
serializer_class = serializers.ChangeSecretRecordSerializer
|
2022-11-09 05:34:29 +00:00
|
|
|
filter_fields = ['asset', 'execution_id']
|
|
|
|
search_fields = ['asset__hostname']
|
2022-11-08 09:54:51 +00:00
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
return ChangeSecretRecord.objects.all()
|
|
|
|
|
|
|
|
def filter_queryset(self, queryset):
|
|
|
|
queryset = super().filter_queryset(queryset)
|
|
|
|
eid = self.request.GET.get('execution_id')
|
|
|
|
execution = get_object_or_none(AutomationExecution, pk=eid)
|
|
|
|
if execution:
|
|
|
|
queryset = queryset.filter(execution=execution)
|
2022-11-11 11:15:43 +00:00
|
|
|
queryset = queryset.order_by('-date_started')
|
2022-11-08 09:54:51 +00:00
|
|
|
return queryset
|