generate passwords in validate and pass back through context

This commit is contained in:
Chris Meyers
2015-04-27 14:54:57 -04:00
parent c29e5f40be
commit 8a050dbc97
2 changed files with 19 additions and 2 deletions

View File

@@ -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: