1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 16:51:11 +03:00

Merge pull request #1804 from ryanpetrello/stdout-format-json

never convert ANSI codes to HTML for format /stdout/?format=json
This commit is contained in:
Ryan Petrello 2018-05-16 11:41:20 -04:00 committed by GitHub
commit f287948efe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 6 deletions

View File

@ -4764,7 +4764,6 @@ class UnifiedJobStdout(RetrieveAPIView):
try: try:
target_format = request.accepted_renderer.format target_format = request.accepted_renderer.format
if target_format in ('html', 'api', 'json'): if target_format in ('html', 'api', 'json'):
content_format = request.query_params.get('content_format', 'html')
content_encoding = request.query_params.get('content_encoding', None) 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)
@ -4790,10 +4789,10 @@ class UnifiedJobStdout(RetrieveAPIView):
if target_format == 'api': if target_format == 'api':
return Response(mark_safe(data)) return Response(mark_safe(data))
if target_format == 'json': if target_format == 'json':
if content_encoding == 'base64' and content_format == 'ansi': content = content.encode('utf-8')
return Response({'range': {'start': start, 'end': end, 'absolute_end': absolute_end}, 'content': b64encode(content.encode('utf-8'))}) if content_encoding == 'base64':
elif content_format == 'html': content = b64encode(content)
return Response({'range': {'start': start, 'end': end, 'absolute_end': absolute_end}, 'content': body}) return Response({'range': {'start': start, 'end': end, 'absolute_end': absolute_end}, 'content': content})
return Response(data) return Response(data)
elif target_format == 'txt': elif target_format == 'txt':
return Response(unified_job.result_stdout) return Response(unified_job.result_stdout)

View File

@ -282,7 +282,7 @@ def test_unicode_with_base64_ansi(sqlite_copy_expert, get, admin):
url = reverse( url = reverse(
'api:job_stdout', 'api:job_stdout',
kwargs={'pk': job.pk} kwargs={'pk': job.pk}
) + '?format=json&content_encoding=base64&content_format=ansi' ) + '?format=json&content_encoding=base64'
response = get(url, user=admin, expect=200) response = get(url, user=admin, expect=200)
content = base64.b64decode(json.loads(response.content)['content']) content = base64.b64decode(json.loads(response.content)['content'])