2022-11-08 09:54:51 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
|
|
|
|
from rest_framework import mixins
|
|
|
|
|
2022-12-27 07:27:33 +00:00
|
|
|
from assets import serializers
|
|
|
|
from assets.models import ChangeSecretAutomation, ChangeSecretRecord, AutomationExecution
|
2022-11-08 09:54:51 +00:00
|
|
|
from common.utils import get_object_or_none
|
|
|
|
from orgs.mixins.api import OrgBulkModelViewSet, OrgGenericViewSet
|
2022-12-27 07:27:33 +00:00
|
|
|
from .base import AutomationExecutionViewSet
|
2022-11-08 09:54:51 +00:00
|
|
|
|
|
|
|
__all__ = [
|
2022-12-27 07:27:33 +00:00
|
|
|
'ChangeSecretAutomationViewSet', 'ChangeSecretRecordViewSet',
|
|
|
|
'ChangSecretExecutionViewSet'
|
2022-11-08 09:54:51 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2022-12-27 07:27:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ChangSecretExecutionViewSet(AutomationExecutionViewSet):
|
|
|
|
rbac_perms = (
|
|
|
|
("list", "assets.view_changesecretexecution"),
|
|
|
|
("retrieve", "assets.view_changesecretexecution"),
|
|
|
|
("create", "assets.add_changesecretexecution"),
|
|
|
|
)
|