mirror of
https://github.com/ansible/awx.git
synced 2026-02-20 20:50:06 -03:30
generate passwords in validate and pass back through context
This commit is contained in:
@@ -1712,7 +1712,7 @@ class JobLaunchSerializer(BaseSerializer):
|
||||
if obj and hasattr(view, '_raw_data_form_marker'):
|
||||
if obj.passwords_needed_to_start:
|
||||
password_keys = dict([(p, u'') for p in obj.passwords_needed_to_start])
|
||||
res.update(dict(extra_vars=password_keys))
|
||||
res.update(password_keys)
|
||||
if self.get_credential_needed_to_start(obj) is True:
|
||||
res.update(dict(credential=''))
|
||||
return res
|
||||
@@ -1733,6 +1733,20 @@ class JobLaunchSerializer(BaseSerializer):
|
||||
attrs[source] = credential
|
||||
return attrs
|
||||
|
||||
def validate_passwords_needed_to_start(self, attrs, source):
|
||||
obj = self.context.get('obj')
|
||||
passwords = self.context.get('passwords')
|
||||
data = self.context.get('data')
|
||||
|
||||
# fill passwords dict with request data passwords
|
||||
if obj.passwords_needed_to_start:
|
||||
try:
|
||||
for p in obj.passwords_needed_to_start:
|
||||
passwords[p] = data.get(p)
|
||||
except KeyError:
|
||||
raise serializers.ValidationError(obj.passwords_needed_to_start)
|
||||
return attrs
|
||||
|
||||
def validate_extra_vars(self, attrs, source):
|
||||
extra_vars = attrs.get(source, {})
|
||||
if not extra_vars:
|
||||
|
||||
Reference in New Issue
Block a user