VRO Literal Map Viewer

The following snippet of code – I did not write, This will not become a theme… But it has become so useful to me, I wanted to have my own beautified jsdoc reference to it.

https://communities.vmware.com/thread/609702

thanks qc4vmware

/**
* converts literal map to a JSON string
* @param {string} literalMap - literal map in text
* @id 6ecaebc1-c70b-46b2-a2e1-2ce57ef03802
* @version 0.0.1
* @allowedoperations 
* @return {string}
*/
function literalMapViewer(literalMap) {
	var literalMap = extensionData;
	var jsonObj = convertLiteralMapToJson(literalMap);
	var json = JSON.stringify(jsonObj);
	System.debug(json);
	
	return json
	
	function convertLiteralMapToJson(literalMap) {
	    var mapObj = {};
	    for each(var key in literalMap.keySet()) {
	        var obj = literalMap.get(key);
	        var className = System.getObjectClassName(obj);
	
	        if (className == "vCACCAFEStringLiteral" || "vCACCAFEDateTimeLiteral" || "vCACCAFEIntegerLiteral" ||
	            "vCACCAFEBooleanLiteral" || "vCACCAFEDecimalLiteral" || "vCACCAFESecureStringLiteral") mapObj[key] = obj.getValue();
	
	        if (className == "vCACCAFEComplexLiteral") mapObj[key] = convertComplexLiteralToJson(obj);
	
	        if (className == "vCACCAFEMultipleLiteral") {
	            multClassName = System.getObjectClassName(obj.getValue());
	            mapObj[key] = [];
	            for each(var item in obj.getValue()) {
	                var itemClassName = System.getObjectClassName(item);
	                if (itemClassName == "vCACCAFEComplexLiteral") {y
	                    mapObj[key].push(convertComplexLiteralToJson(item));
	                }
	                else {
	                    System.debug("unhandled itemClassName::" + itemClassName);
	                }
	            }
	        }
	
	        if (className == "vCACCAFEEntityReference") {
	            mapObj[key] = {};
	            mapObj[key].referenceType = "vCACCAFEEntityReference";
	            mapObj[key].classId = obj.getClassId();
	            mapObj[key].componentId = obj.getComponentId();
	            mapObj[key].id = obj.getId();
	            mapObj[key].label = obj.getLabel();
	            mapObj[key].typeId = obj.getTypeId();
	            mapObj[key].label = obj.getLabel();
	        }
	
	        if (mapObj[key] == undefined) {
	            System.log(key + " unhandled className::" + className);
	            mapObj[key] = "QCconvertLiteralMapToJson: This mapping has an unhandled class for key:" + key + ", class: " + classname;
	        }
	    };
	    return mapObj;
	};
	
	function convertComplexLiteralToJson(complexLiteral) {
	    var complexClass = System.getObjectClassName(complexLiteral.getValue());
	    if (complexClass == "vCACCAFELiteralMap") {
	        return convertLiteralMapToJson(complexLiteral.getValue());
	    }
	    else {
	        System.log("not sure what to do with complexClass::" + complexClass);
	        return "QCconvertComplexLiteralToJson: This complex literal has an unhandled class:" + complexClass;
	    }
	}
};
Advertisements

Temporary Lower Certificate security to connect VRA VRO

PowerVRA and PowerVRO do a fantastic job at assisting with connecting to VRO and VRA. When working with Self Signed certificates, using the switch “–IgnoreCertRequirements” will usually allow connection to proceed. Occasionally a more drastic approach is required. 

I often use the following bit of code to enable the connection. I do apologise for not being state the source of this, I have had it save in my library for quite a while and usually use it as is.

if (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type)
{
$certCallback = @"
    using System;
    using System.Net;
    using System.Net.Security;
    using System.Security.Cryptography.X509Certificates;
    public class ServerCertificateValidationCallback
    {
        public static void Ignore()
        {
            if(ServicePointManager.ServerCertificateValidationCallback ==null)
            {
                ServicePointManager.ServerCertificateValidationCallback += 
                    delegate
                    (
                        Object obj, 
                        X509Certificate certificate, 
                        X509Chain chain, 
                        SslPolicyErrors errors
                    )
                    {
                        return true;
                    };
            }
        }
    }
"@
    Add-Type $certCallback
 }
[ServerCertificateValidationCallback]::Ignore()

$SecurityProtocols = @(
        [System.Net.SecurityProtocolType]::Ssl3,
        [System.Net.SecurityProtocolType]::Tls,
        [System.Net.SecurityProtocolType]::Tls12
    )
    [System.Net.ServicePointManager]::SecurityProtocol = $SecurityProtocols -join ","