1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 16:51:11 +03:00

Merge pull request #164 from chrismeyersfsu/extra_vars

validate extra_vars, but get them from request.DATA
This commit is contained in:
Chris Meyers 2015-04-27 16:23:45 -04:00
commit c8da42f7ac
2 changed files with 8 additions and 9 deletions

View File

@ -6,7 +6,6 @@ import json
import re import re
import logging import logging
from dateutil import rrule from dateutil import rrule
from ast import literal_eval
# PyYAML # PyYAML
import yaml import yaml
@ -1759,15 +1758,14 @@ class JobLaunchSerializer(BaseSerializer):
def validate_extra_vars(self, attrs, source): def validate_extra_vars(self, attrs, source):
extra_vars = attrs.get(source, {}) extra_vars = attrs.get(source, {})
if not extra_vars:
return attrs
try: try:
extra_vars = literal_eval(extra_vars) extra_vars = json.loads(extra_vars)
attrs['extra_vars'] = extra_vars except (ValueError, TypeError):
except Exception: try:
if not isinstance(extra_vars, dict): extra_vars = yaml.safe_load(extra_vars)
raise serializers.ValidationError("Invalid format. JSON expected.") except (yaml.YAMLError, TypeError):
raise serializers.ValidationError('Must be valid JSON or YAML')
return attrs return attrs
def validate_variables_needed_to_start(self, attrs, source): def validate_variables_needed_to_start(self, attrs, source):

View File

@ -1455,8 +1455,9 @@ class JobTemplateLaunch(RetrieveAPIView, GenericAPIView):
kv = { kv = {
'credential': serializer.object.credential.pk, 'credential': serializer.object.credential.pk,
'extra_vars': serializer.object.extra_vars
} }
if 'extra_vars' in request.DATA:
kv['extra_vars'] = request.DATA['extra_vars']
kv.update(passwords) kv.update(passwords)
new_job = obj.create_unified_job(**kv) new_job = obj.create_unified_job(**kv)