mirror of
https://github.com/ansible/awx.git
synced 2026-03-11 06:29:31 -02:30
more accurate handling of serializer cred versioning
This commit is contained in:
@@ -3097,7 +3097,6 @@ class JobTemplateSerializer(JobTemplateMixin, UnifiedJobTemplateSerializer, JobO
|
|||||||
def get_summary_fields(self, obj):
|
def get_summary_fields(self, obj):
|
||||||
summary_fields = super(JobTemplateSerializer, self).get_summary_fields(obj)
|
summary_fields = super(JobTemplateSerializer, self).get_summary_fields(obj)
|
||||||
all_creds = []
|
all_creds = []
|
||||||
extra_creds = []
|
|
||||||
if obj.pk:
|
if obj.pk:
|
||||||
for cred in obj.credentials.all():
|
for cred in obj.credentials.all():
|
||||||
summarized_cred = {
|
summarized_cred = {
|
||||||
@@ -3108,20 +3107,31 @@ class JobTemplateSerializer(JobTemplateMixin, UnifiedJobTemplateSerializer, JobO
|
|||||||
'credential_type_id': cred.credential_type_id
|
'credential_type_id': cred.credential_type_id
|
||||||
}
|
}
|
||||||
all_creds.append(summarized_cred)
|
all_creds.append(summarized_cred)
|
||||||
if self.is_detail_view:
|
# Organize credential data into multitude of deprecated fields
|
||||||
for summarized_cred in all_creds:
|
extra_creds = []
|
||||||
if summarized_cred['kind'] in ('cloud', 'net'):
|
vault_credential = None
|
||||||
extra_creds.append(summarized_cred)
|
credential = None
|
||||||
elif summarized_cred['kind'] == 'ssh':
|
for summarized_cred in all_creds:
|
||||||
summary_fields['credential'] = summarized_cred
|
if summarized_cred['kind'] in ('cloud', 'net'):
|
||||||
elif summarized_cred['kind'] == 'vault':
|
extra_creds.append(summarized_cred)
|
||||||
summary_fields['vault_credential'] = summarized_cred
|
elif summarized_cred['kind'] == 'ssh':
|
||||||
|
credential = summarized_cred
|
||||||
|
elif summarized_cred['kind'] == 'vault':
|
||||||
|
vault_credential = summarized_cred
|
||||||
|
# Selectively apply those fields, depending on view deetails
|
||||||
|
if (self.is_detail_view or self.version == 1) and credential:
|
||||||
|
summary_fields['credential'] = credential
|
||||||
|
else:
|
||||||
|
# Credential could be an empty dictionary in this case
|
||||||
|
summary_fields.pop('credential', None)
|
||||||
|
if (self.is_detail_view or self.version == 1) and vault_credential:
|
||||||
|
summary_fields['vault_credential'] = vault_credential
|
||||||
|
else:
|
||||||
|
# vault credential could be empty dictionary
|
||||||
|
summary_fields.pop('vault_credential', None)
|
||||||
if self.version > 1:
|
if self.version > 1:
|
||||||
if self.is_detail_view:
|
if self.is_detail_view:
|
||||||
summary_fields['extra_credentials'] = extra_creds
|
summary_fields['extra_credentials'] = extra_creds
|
||||||
else:
|
|
||||||
# Credential would be an empty dictionary in this case
|
|
||||||
summary_fields.pop('credential', None)
|
|
||||||
summary_fields['credentials'] = all_creds
|
summary_fields['credentials'] = all_creds
|
||||||
return summary_fields
|
return summary_fields
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user