Create vcLogin.js

This commit is contained in:
John Bowdre 2022-06-14 09:02:11 -05:00 committed by GitHub
parent 6d81f69b9a
commit 97e3d47f43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,13 @@
/* JavaScript: vcLogin action
Retrieves a login token to a vCenter REST endpoint.
Inputs: vCenterName (string)
Return type: string
*/
var host = System.getModule("com.virtuallypotato.utility").getConfigValue("vPotato", "Endpoints", vCenterName).host;
var request = host.createRequest("POST", "/api/session");
request.setHeader("Content-Type", "application/json");
var response = request.execute();
var token = JSON.parse(response.contentAsString);
System.debug("Created vCenter API session: " + token);
return token;