Last active
September 12, 2019 23:25
-
-
Save trisharia/4262427728b9ca2f22f76c39a5521768 to your computer and use it in GitHub Desktop.
Authenticate against VMware Cloud Services via REST using a transient RESTHost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// VMware vRealize Orchestrator action sample | |
// | |
// Authenticates against VMware Cloud Services via REST using a transient RESTHost. | |
// Assumes the presence of action System.getModule("com.vmware.pso.rest").executeTransientRESTOperation | |
// Obtain the action here: https://gist.github.com/trisharia/7b62fcdf12600511b3d7e9b635981b2c | |
// | |
// For vRA Cloud 7.0+ and vRA 8.0+ | |
// | |
// Action Inputs: | |
// cspBaseUrl - string - Base URL for connecting to VMware Cloud Services RESTful API | |
// e.g., https://api.mgmt.cloud.vmware.com | |
// cspApiToken - string - VMware Cloud Services API token providing access per organization | |
// See https://docs.vmware.com/en/VMware-Cloud-services/services/Using-VMware-Cloud-Services/GUID-E2A3B1C1-E9AD-4B00-A6B6-88D31FCDDF7C.html | |
// | |
// Return type: string - The authentication bearer token for performing REST operations against any of the VMward Cloud Services, such as VMware Cloud Assembly | |
const opMethod = "POST"; | |
const opUrl = "/iaas/login"; | |
const contentType = "application/json"; | |
var contentJson = { | |
"host":"127.0.0.1", | |
"refreshToken": cspApiToken | |
}; | |
var content = JSON.stringify(contentJson); | |
var opResponse = System.getModule("com.vmware.pso.rest").executeTransientRESTOperation( | |
cspBaseUrl,null,null,opMethod,opUrl,null,null,contentType,content); | |
if (opResponse.statusCode >= 400) { | |
throw "Failed to get access token (" + opResponse.statusCode + " Error). Details: " + opResponse.responseString; | |
} | |
var responseJson = JSON.parse(opResponse.responseString); | |
var authToken = responseJson.token; | |
return authToken; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment