mirror of
https://github.com/ansible/awx.git
synced 2026-02-23 22:16:00 -03:30
Merge pull request #2079 from AlanCoding/creds_no_op
Allow no-op case when modifying deprecated credentials
This commit is contained in:
@@ -2092,14 +2092,14 @@ class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOpt
|
||||
def _update_deprecated_fields(self, fields, obj):
|
||||
if 'credential' in fields:
|
||||
new_cred = fields['credential']
|
||||
existing_creds = obj.credentials.exclude(credential_type__kind='vault')
|
||||
for cred in existing_creds:
|
||||
# Remove all other cloud credentials
|
||||
if cred != new_cred:
|
||||
existing = obj.credentials.all()
|
||||
if new_cred not in existing:
|
||||
for cred in existing:
|
||||
# Remove all other cloud credentials
|
||||
obj.credentials.remove(cred)
|
||||
if new_cred:
|
||||
# Add new credential
|
||||
obj.credentials.add(new_cred)
|
||||
if new_cred:
|
||||
# Add new credential
|
||||
obj.credentials.add(new_cred)
|
||||
|
||||
def validate(self, attrs):
|
||||
deprecated_fields = {}
|
||||
@@ -2889,11 +2889,12 @@ class JobOptionsSerializer(LabelsListMixin, BaseSerializer):
|
||||
('network_credential', obj.network_credentials),
|
||||
):
|
||||
if key in fields:
|
||||
for cred in existing:
|
||||
obj.credentials.remove(cred)
|
||||
if fields[key]:
|
||||
obj.credentials.add(fields[key])
|
||||
obj.save()
|
||||
new_cred = fields[key]
|
||||
if new_cred not in existing:
|
||||
for cred in existing:
|
||||
obj.credentials.remove(cred)
|
||||
if new_cred:
|
||||
obj.credentials.add(new_cred)
|
||||
|
||||
def validate(self, attrs):
|
||||
v1_credentials = {}
|
||||
@@ -3772,10 +3773,13 @@ class WorkflowJobTemplateNodeSerializer(LaunchConfigurationBaseSerializer):
|
||||
deprecated_fields['credential'] = validated_data.pop('credential')
|
||||
obj = super(WorkflowJobTemplateNodeSerializer, self).update(obj, validated_data)
|
||||
if 'credential' in deprecated_fields:
|
||||
for cred in obj.credentials.filter(credential_type__kind='ssh'):
|
||||
obj.credentials.remove(cred)
|
||||
if deprecated_fields['credential']:
|
||||
obj.credentials.add(deprecated_fields['credential'])
|
||||
existing = obj.credentials.filter(credential_type__kind='ssh')
|
||||
new_cred = deprecated_fields['credential']
|
||||
if new_cred not in existing:
|
||||
for cred in existing:
|
||||
obj.credentials.remove(cred)
|
||||
if new_cred:
|
||||
obj.credentials.add(new_cred)
|
||||
return obj
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user