Last active
July 11, 2022 10:53
-
-
Save sammcgeown/0e2137ac27597e522280e22a68ecbed9 to your computer and use it in GitHub Desktop.
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
// Build the Vault URL | |
url = "https://" + vaultServer + ":" + vaultPort; | |
// Import the Vault SSL certificate | |
var ld = Config.getKeystores().getImportCAFromUrlAction(); | |
var model = ld.getModel(); | |
model.value = url; | |
error = ld.execute(); | |
// Create REST call | |
var uri = url + "/v1/auth/userpass/login/" + vaultUser; | |
var method = "POST"; | |
method = method.toUpperCase(); | |
// Create a dynamic REST host | |
var httpRestHost = null; | |
var restHost = RESTHostManager.createHost("dynamicRequest"); | |
restHost.operationTimeout = 900; | |
httpRestHost = RESTHostManager.createTransientHostFrom(restHost); | |
httpRestHost.operationTimeout = 900; | |
// Remove the endpoint from the URI: | |
var urlEndpointSplit = uri.split("/"); | |
var urlEndpoint = urlEndpointSplit[urlEndpointSplit.length - 1]; | |
uri = uri.split(urlEndpoint)[0]; | |
httpRestHost.url = uri; | |
httpRestHost.hostVerification = false; | |
// Build the JSON body | |
var requestBody = { | |
"password": vaultPassword | |
} | |
var request = httpRestHost.createRequest(method, urlEndpoint, JSON.stringify(requestBody)); | |
request.contentType = "application/json"; | |
var response = request.execute(); | |
if (response.contentAsString){ | |
var output = JSON.parse(response.contentAsString); | |
return output.auth.client_token | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment