Skip to content

Instantly share code, notes, and snippets.

View imtrinity94's full-sized avatar
💭
Blogging

Mayank Goyal imtrinity94

💭
Blogging
View GitHub Profile
@imtrinity94
imtrinity94 / vRO_logPayloadProperties.js
Created March 31, 2023 15:08 — forked from mpoore/logPayloadProperties.js
vRO action that logs the content of a Properties object
System.log("==== Begin: vRA Event Broker Payload Properties ====");
logAllProperties(payload,0);
System.log("==== End: vRA Event Broker Payload Properties ====");
function logAllProperties(props,indent) {
var keys = (props.keys).sort();
for each (var key in keys) {
var prop = props.get(key);
var type = System.getObjectType(prop);
if (type == "Properties") {
@imtrinity94
imtrinity94 / vRO_bulkUpdateActionScripts.js
Created March 31, 2023 12:42
vRO script to update scripts of all actions inside a vRO action module
/**
* vRO script to update scripts of all actions inside a vRO action module
*
* @version 1.0.0
*
* @param {Module} actionModule
*
* @outputType string
*
*/
@imtrinity94
imtrinity94 / vro_sortIPAddresses.js
Created March 27, 2023 11:07
IP Sorter for vRO
// the array of the IP Address
// Custom Comparator to sort the
// Array in the increasing order
function customComparator(a, b){
// Breaking into the octets
var octetsA = a.split(".");
var octetsB = b.split(".");
@imtrinity94
imtrinity94 / vroAction_getvRABearerToken.js
Created March 27, 2023 08:03
Generate vRA Bearer Token using vRO Action
if(arguments.callee.name.substr(6)) System.setLogMarker("ACTION: "+arguments.callee.name.substr(6));
var vraRestHost = vraHost.createRestClient();
System.log("vRA hostname: "+vraHost.name);
var loginObj = {};
loginObj.domain = domain;
loginObj.password = password;
loginObj.username = username;
var loginBody = JSON.stringify(loginObj);
var operationUrl = "/csp/gateway/am/api/login";
@imtrinity94
imtrinity94 / vRO_function_bind.js
Created March 22, 2023 07:48
Function Binding in vRO
const module = {
x: 42,
getX: function() {
return this.x;
}
};
const unboundGetX = module.getX;
System.log(unboundGetX()); // The function gets invoked at the global scope
// expected output: undefined
@imtrinity94
imtrinity94 / Using arguments.callee.js
Created March 21, 2023 10:12
Using arguments.callee in an anonymous recursive function
/* Using arguments.callee in an anonymous recursive function
A recursive function must be able to refer to itself. Typically, a function refers to itself by its name. However, an anonymous function (which can be created by a function expression or the Function constructor) does not have a name. Therefore if there is no accessible variable referring to it, the only way the function can refer to itself is by arguments.callee.
The following example defines a function, which, in turn, defines and returns a factorial function. This example isn't very practical, and there are nearly no cases where the same result cannot be achieved with named function expressions. */
function create() {
return function (n) {
if (n <= 1) {
return 1;
}
@imtrinity94
imtrinity94 / gist:9cca4e04753435483ecb976d424771c3
Created March 21, 2023 09:56
The Y-combinator: a utility function
// The Y-combinator: a utility function!
var Y = function Y(hof) {
return function (x) {
return x(x);
}(function (x) {
return hof(function (y) {
return x(x)(y);
});
});
};
@imtrinity94
imtrinity94 / vRA_Pagination.js
Last active March 27, 2023 08:04
How to handle vRA Pagination using vRO Code
//Assumimg vRA 8.x plugin is already installed in vRO
// typeof host = vRA:Host
var restClient = host.createRestClient();
var items = [];
var path = "/deployment/api/deployments"; // or any other API path
var page = 0;
var page_size = 200; // smaller page_size means more pages to parse
var base_path = path + "?$top=" + page_size;
while (true) {
var skipFilter = page * page_size;
@imtrinity94
imtrinity94 / vro_base64conversion.js
Last active March 21, 2023 10:44
vRO code to base64 encode decode
/**
*
* Base64 encode / decode
* http://www.webtoolkit.info/
*
**/
// How to use
// console.log(Base64.encode("username:pa$$w0rd!")); => dXNlcm5hbWU6cGEkJHcwcmQh
var Base64 = {
@imtrinity94
imtrinity94 / validate NSS authorization.js
Last active March 10, 2023 09:37
validate NSS REST authorization vRO Script [x-www-form-urlencoded]
/**
*
* @param {string} grantType nss.accesskey
* @param {string} accessId
* @param {SecureString} secretKey
* @param {REST:RESTHost} RESTHost NSSHost
* @outputType boolean
*
*/