Merge pull request #4080 from cchurch/event-stdout-max-bytes-display

Add configurable limit to size of stdout shown for a single job event
This commit is contained in:
Chris Church
2016-11-22 14:50:38 -05:00
committed by GitHub
3 changed files with 33 additions and 0 deletions

View File

@@ -2489,6 +2489,16 @@ class JobEventSerializer(BaseSerializer):
pass
return d
def to_representation(self, obj):
ret = super(JobEventSerializer, self).to_representation(obj)
# Show full stdout for event detail view, truncate only for list view.
if hasattr(self.context.get('view', None), 'retrieve'):
return ret
max_bytes = settings.EVENT_STDOUT_MAX_BYTES_DISPLAY
if max_bytes > 0 and 'stdout' in ret and len(ret['stdout']) >= max_bytes:
ret['stdout'] = ret['stdout'][:(max_bytes - 1)] + u'\u2026'
return ret
class AdHocCommandEventSerializer(BaseSerializer):
@@ -2510,6 +2520,16 @@ class AdHocCommandEventSerializer(BaseSerializer):
res['host'] = reverse('api:host_detail', args=(obj.host.pk,))
return res
def to_representation(self, obj):
ret = super(JobEventSerializer, self).to_representation(obj)
# Show full stdout for event detail view, truncate only for list view.
if hasattr(self.context.get('view', None), 'retrieve'):
return ret
max_bytes = settings.EVENT_STDOUT_MAX_BYTES_DISPLAY
if max_bytes > 0 and 'stdout' in ret and len(ret['stdout']) >= max_bytes:
ret['stdout'] = ret['stdout'][:(max_bytes - 1)] + u'\u2026'
return ret
class JobLaunchSerializer(BaseSerializer):