From c16c6a54f2770bcb0a5ccaa1c3158cccfa9acfc4 Mon Sep 17 00:00:00 2001 From: John Bowdre <61015723+jbowdre@users.noreply.github.com> Date: Tue, 14 Jun 2022 08:48:20 -0500 Subject: [PATCH] Create vraLogin.js --- .../com.virtuallypotato.utility/vraLogin.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Orchestrator/Actions/com.virtuallypotato.utility/vraLogin.js diff --git a/Orchestrator/Actions/com.virtuallypotato.utility/vraLogin.js b/Orchestrator/Actions/com.virtuallypotato.utility/vraLogin.js new file mode 100644 index 0000000..425ab0e --- /dev/null +++ b/Orchestrator/Actions/com.virtuallypotato.utility/vraLogin.js @@ -0,0 +1,19 @@ +/* JavaScript: vraLogin action + Retrieves a login token to a vRA REST endpoint. + Inputs: none + Return type: string +*/ +var restHost = System.getModule("com.virtuallypotato.utility").getConfigValue("vPotato", "Endpoints", "vRAHost"); +var host = restHost.host; +var loginObj = { + domain: restHost.domain, + password: restHost.password, + username: restHost.username +}; +var loginJson = JSON.stringify(loginObj); +var request = host.createRequest("POST", "/csp/gateway/am/api/login", loginJson); +request.setHeader("Content-Type", "application/json"); +var response = request.execute(); +var token = JSON.parse(response.contentAsString).cspAuthToken; +System.debug("Created vRA API session: " + token); +return token;