Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_serializer_class(self):
if self.action == "list":
return serializers.ListTaskSerializer
elif self.action == "retrieve":
return serializers.DetailedTaskSerializer
else:
# create/update/destroy
return serializers.TaskSerializer
def get_serializer_class(self):
if self.action == "list":
return serializers.ListLabelSerializer
elif self.action == "retrieve":
return serializers.DetailedLabelSerializer
else:
# create/update/destroy
return serializers.LabelSerializer
def get_serializer_class(self):
if self.action == "list":
return serializers.ListHostSerializer
elif self.action == "retrieve":
return serializers.DetailedHostSerializer
else:
# create/update/destroy
return serializers.HostSerializer
def get_serializer_class(self):
if self.action == "list":
return serializers.ListPlaySerializer
elif self.action == "retrieve":
return serializers.DetailedPlaySerializer
else:
# create/update/destroy
return serializers.PlaySerializer
def get(self, request, *args, **kwargs):
# Results can contain a wide array of non-ascii or binary characters, escape them
codecs.register_error("strict", codecs.lookup_error("surrogateescape"))
result = self.get_object()
serializer = serializers.DetailedResultSerializer(result)
return Response({"result": serializer.data})
def get_serializer_class(self):
if self.action == "list":
return serializers.ListFileSerializer
elif self.action == "retrieve":
return serializers.DetailedFileSerializer
else:
# create/update/destroy
return serializers.FileSerializer
def handle(self, *args, **options):
path = options.get("path")
self.create_dirs(path)
# TODO: Leverage ui views directly instead of duplicating logic here
query = models.Playbook.objects.all()
serializer = serializers.ListPlaybookSerializer(query.all(), many=True)
print("[ara] Generating static files for %s playbooks at %s..." % (query.count(), path))
# Index
destination = os.path.join(path, "index.html")
data = {"playbooks": serializer.data, "static_generation": True, "page": "index"}
self.render("index.html", destination, **data)
# Escape surrogates to prevent UnicodeEncodeError exceptions
codecs.register_error("strict", codecs.lookup_error("surrogateescape"))
# Playbooks
for playbook in query.all():
destination = os.path.join(path, "playbook/%s.html" % playbook.id)
serializer = serializers.DetailedPlaybookSerializer(playbook)
data = {"playbook": serializer.data, "static_generation": True}
def get_serializer_class(self):
if self.action == "list":
return serializers.ListResultSerializer
elif self.action == "retrieve":
return serializers.DetailedResultSerializer
else:
# create/update/destroy
return serializers.ResultSerializer
def get(self, request, *args, **kwargs):
host = self.get_object()
serializer = serializers.DetailedHostSerializer(host)
return Response({"host": serializer.data})
def get_serializer_class(self):
if self.action == "list":
return serializers.ListPlaybookSerializer
elif self.action == "retrieve":
return serializers.DetailedPlaybookSerializer
else:
# create/update/destroy
return serializers.PlaybookSerializer