From f4ac4a0bf9c497320731f2f5cb9548ca9a6d9f3c Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Fri, 31 Oct 2014 11:23:57 -0400 Subject: [PATCH] Variable parsing added a check for variables that are passed with double curly brackets '{{}}' and JT throws an error and doesn't save now --- awx/ui/static/js/controllers/JobTemplates.js | 3 +++ awx/ui/static/js/helpers/Variables.js | 11 ++++++++++- awx/ui/static/lib/ansible/Socket.js | 9 +-------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/awx/ui/static/js/controllers/JobTemplates.js b/awx/ui/static/js/controllers/JobTemplates.js index 54c4b376d6..01d0e843cb 100644 --- a/awx/ui/static/js/controllers/JobTemplates.js +++ b/awx/ui/static/js/controllers/JobTemplates.js @@ -907,6 +907,9 @@ function JobTemplatesEdit($scope, $rootScope, $compile, $location, $log, $routeP try { // Make sure we have valid variable data data.extra_vars = ToJSON($scope.parseType, $scope.variables, true); + if(data.extra_vars === undefined ){ + throw 'undefined variables'; + } for (fld in form.fields) { if (form.fields[fld].type === 'select' && fld !== 'playbook') { data[fld] = $scope[fld].value; diff --git a/awx/ui/static/js/helpers/Variables.js b/awx/ui/static/js/helpers/Variables.js index 70d74161d7..b9aaaa1917 100644 --- a/awx/ui/static/js/helpers/Variables.js +++ b/awx/ui/static/js/helpers/Variables.js @@ -126,6 +126,15 @@ angular.module('VariablesHelper', ['Utilities']) // else json_data = jsyaml.load(variables); + $.each( json_data, function( key, value ) { + console.log( key + ": " + value ); + if(value.toString() === "[object Object]"){ + //$log.error('Failed to parse YAML string. Parser returned ' + key + ' : ' + value + '.'); + + throw 'Failed to parse YAML string. Parser returned ' + key + ' : ' + value + '.'; + } + }); + } catch(e) { @@ -146,7 +155,7 @@ angular.module('VariablesHelper', ['Utilities']) result = json_data; if (stringify) { if ($.isEmptyObject(json_data)) { - result = ""; + result = undefined; } else { result = JSON.stringify(json_data, undefined, '\t'); } diff --git a/awx/ui/static/lib/ansible/Socket.js b/awx/ui/static/lib/ansible/Socket.js index fc36d7ddea..9dc7c9cd92 100644 --- a/awx/ui/static/lib/ansible/Socket.js +++ b/awx/ui/static/lib/ansible/Socket.js @@ -71,17 +71,10 @@ angular.module('SocketIO', ['AuthService', 'Utilities']) // We have a valid session token, so attempt socket connection $log.debug('Socket connecting to: ' + url); self.scope.socket_url = url; - // handshakeData = { - // headers: { - // 'Authorization': 'Token ' + token, - // 'X-Auth-Token': 'Token ' + token - // } - // } - self.socket = io.connect(url, { headers: { - 'Authorization': 'Token ' + token, + 'Authorization': 'Token ' + token, // i don't think these are actually inserted into the header--jt 'X-Auth-Token': 'Token ' + token }, 'connect timeout': 3000,