From ae9032ce037885c2cc0a7a415fd6cb2877e2c2db Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Thu, 13 Jun 2019 17:14:08 -0400 Subject: [PATCH] fix a bug introduced in the inventory source detail API by v1 removal see: https://github.com/ansible/awx/issues/4059 --- awx/api/serializers.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 1a2eaaea2d5e..fbb01f0f2a59 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -1943,6 +1943,25 @@ def validate(self, attrs): return super(InventorySourceOptionsSerializer, self).validate(attrs) + # TODO: remove when old 'credential' fields are removed + def get_summary_fields(self, obj): + summary_fields = super(InventorySourceOptionsSerializer, self).get_summary_fields(obj) + all_creds = [] + if 'credential' in summary_fields: + cred = obj.get_cloud_credential() + if cred: + summarized_cred = { + 'id': cred.id, 'name': cred.name, 'description': cred.description, + 'kind': cred.kind, 'cloud': True + } + summary_fields['credential'] = summarized_cred + all_creds.append(summarized_cred) + summary_fields['credential']['credential_type_id'] = cred.credential_type_id + else: + summary_fields.pop('credential') + summary_fields['credentials'] = all_creds + return summary_fields + class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOptionsSerializer):