Validate against ansible variables on ad hoc launch

Share code between this check for ad hoc and JT callback
This commit is contained in:
AlanCoding
2017-10-05 12:14:05 -04:00
parent 02e3f45422
commit eacbeef660
5 changed files with 40 additions and 13 deletions

View File

@@ -45,7 +45,7 @@ from awx.main.fields import ImplicitRoleField
from awx.main.utils import (
get_type_for_model, get_model_for_type, timestamp_apiformat,
camelcase_to_underscore, getattrd, parse_yaml_or_json,
has_model_field_prefetched)
has_model_field_prefetched, extract_ansible_vars)
from awx.main.utils.filters import SmartFilter
from awx.main.validators import vars_validate_or_raise
@@ -2759,6 +2759,14 @@ class AdHocCommandSerializer(UnifiedJobSerializer):
ret['name'] = obj.module_name
return ret
def validate_extra_vars(self, value):
redacted_extra_vars, removed_vars = extract_ansible_vars(value)
if removed_vars:
raise serializers.ValidationError(_(
"Variables {} are prohibited from use in ad hoc commands."
).format(",".join(removed_vars)))
return vars_validate_or_raise(value)
class AdHocCommandCancelSerializer(AdHocCommandSerializer):