/**
* This action creates an XML file with all details of all existing
* actions and its script code in the log.
*
* @name getActions
* @param {string} in_userName - Name of the user
* @param {SecureString} in_password - Password of the user
* @param {string} in_moduleFilter - Search for substring in module, optional
* @param {string} in_nameFilter - Search for substring in name, optional
*
* @author Stefan Schnell <mail@stefan-schnell.de>
* @license MIT
* @version 1.4.1
*
* Checked with release 8.12.0, 8.14.1 and 8.16.2
*/
var _getActionsNS = {
/**
* _escapeXML
*
* Escapes characters in a string, which could be misinterpreted as
* markup in XML.
*
* @name escapeXML
* @param {string} strXML - XML which characters to convert
* @returns {string} Converted XML
*/
_escapeXML : function(strXML) {
if (strXML) {
return strXML.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
/*
.replace(/\u00e4/g, "ae")
.replace(/\u00c4/g, "Ae")
.replace(/\u00f6/g, "oe")
.replace(/\u00d6/g, "Oe")
.replace(/\u00fc/g, "ue")
.replace(/\u00dc/g, "Ue")
.replace(/\u00df/g, "ss");
*/
}
},
Main : function(userName, password, moduleFilter, nameFilter) {
var output = "<?xml version=\"1.0\"?>";
output += "<actions>";
try {
var actions =
System.getModule("com.vmware.library.action").getAllActions();
// Search for substring in module
if (moduleFilter) {
// Reverse search in actions array to ...
for (var i = actions.length - 1; i >= 0; i--) {
if (actions[i].module.name.indexOf(moduleFilter) === -1) {
// delete element if moduleFilter not found in module name
actions.splice(i, 1);
}
}
}
// Search for substring in script name
if (nameFilter) {
// Reverse search in actions array to ...
for (var i = actions.length - 1; i >= 0; i--) {
if (actions[i].name.indexOf(nameFilter) === -1) {
// delete element if nameFilter not found in script name
actions.splice(i, 1);
}
}
}
actions.forEach( function(action) {
output += "<action module=\"" + action.module.name +
"\" name=\"" + _getActionsNS._escapeXML(action.name) + "\">";
// General
output += "<id>" + action.id + "</id>";
if (action.description) {
var actionDescription = action.description.replace(/[\r\n]/gm, '');
output += "<description>" +
_getActionsNS._escapeXML(actionDescription) + "</description>";
} else {
output += "<description/>";
}
output += "<version>" + action.version + "</version>";
// Runtime if available
var runtime = System.getModule("de.stschnell").getActionInformation(
userName,
password,
action.module.name,
action.name
).runtime;
if (runtime) {
output += "<runtime>" + runtime + "</runtime>";
}
// Script > Properties > Inputs
var parameters = action.parameters;
output += "<inputs>";
parameters.forEach( function(parameter) {
output += "<input>";
output += "<name>" +
_getActionsNS._escapeXML(parameter.name) + "</name>";
output += "<type>" + parameter.type + "</type>";
if (parameter.description) {
output += "<description>" +
_getActionsNS._escapeXML(parameter.description) +
"</description>";
} else {
output += "<description/>";
}
output += "</input>";
});
output += "</inputs>";
// Script > Properties > Return type
output += "<returnType>" + action.returnType +
"</returnType>";
// Script > Code
output += "<script>";
if (action.script) {
output += _getActionsNS._escapeXML(action.script);
}
output += "</script>";
output += "</action>";
});
output += "</actions>";
} catch(e) {
System.log(e);
System.log(e.stack);
} finally {
System.log(output);
}
}
}
// Main
if (
String(in_userName).trim() !== "" &&
String(in_password).trim() !== ""
) {
_getActionsNS.Main(
in_userName,
in_password,
in_moduleFilter,
in_nameFilter
);
} else {
throw new Error(
"in_userName or in_password argument can not be null"
);
}
|