mirror of
https://github.com/ansible/awx.git
synced 2026-04-10 12:39:22 -02:30
add content encoding for json to stdout
* content_format=ansi&content_encoding=base64 support added to ?format=json on stdout endpoint. Currently the json `content` value is made into html. This change will allow support for consuming STDOUT for display on the terminal.
This commit is contained in:
@@ -11,6 +11,7 @@ import time
|
|||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
import errno
|
import errno
|
||||||
|
from base64 import b64encode
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -2863,6 +2864,8 @@ class UnifiedJobStdout(RetrieveAPIView):
|
|||||||
return Response(response_message)
|
return Response(response_message)
|
||||||
|
|
||||||
if request.accepted_renderer.format in ('html', 'api', 'json'):
|
if request.accepted_renderer.format in ('html', 'api', 'json'):
|
||||||
|
content_format = request.QUERY_PARAMS.get('content_format', 'html')
|
||||||
|
content_encoding = request.QUERY_PARAMS.get('content_encoding', None)
|
||||||
start_line = request.QUERY_PARAMS.get('start_line', 0)
|
start_line = request.QUERY_PARAMS.get('start_line', 0)
|
||||||
end_line = request.QUERY_PARAMS.get('end_line', None)
|
end_line = request.QUERY_PARAMS.get('end_line', None)
|
||||||
dark_val = request.QUERY_PARAMS.get('dark', '')
|
dark_val = request.QUERY_PARAMS.get('dark', '')
|
||||||
@@ -2883,7 +2886,10 @@ class UnifiedJobStdout(RetrieveAPIView):
|
|||||||
if request.accepted_renderer.format == 'api':
|
if request.accepted_renderer.format == 'api':
|
||||||
return Response(mark_safe(data))
|
return Response(mark_safe(data))
|
||||||
if request.accepted_renderer.format == 'json':
|
if request.accepted_renderer.format == 'json':
|
||||||
return Response({'range': {'start': start, 'end': end, 'absolute_end': absolute_end}, 'content': body})
|
if content_encoding == 'base64' and content_format == 'ansi':
|
||||||
|
return Response({'range': {'start': start, 'end': end, 'absolute_end': absolute_end}, 'content': b64encode(content)})
|
||||||
|
elif content_format == 'html':
|
||||||
|
return Response({'range': {'start': start, 'end': end, 'absolute_end': absolute_end}, 'content': body})
|
||||||
return Response(data)
|
return Response(data)
|
||||||
elif request.accepted_renderer.format == 'ansi':
|
elif request.accepted_renderer.format == 'ansi':
|
||||||
return Response(unified_job.result_stdout_raw)
|
return Response(unified_job.result_stdout_raw)
|
||||||
|
|||||||
Reference in New Issue
Block a user