Created
December 4, 2019 15:30
-
-
Save sammcgeown/4cf1ff2b944151443db427b520e3e9ea 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 SSL certificate | |
var ld = Config.getKeystores().getImportCAFromUrlAction(); | |
var model = ld.getModel(); | |
model.value = url; | |
var error = ld.execute(); | |
// Create REST call | |
var uri = url + "/v1/" + vaultSecretPath; | |
var method = "GET"; | |
method = method.toUpperCase(); | |
var httpRestHost = null; | |
// Create a dynamic REST host: | |
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; | |
var request = httpRestHost.createRequest(method, urlEndpoint); | |
request.contentType = "application/json"; | |
request.setHeader("X-VAULT-TOKEN", vaultToken); | |
var response = request.execute(); | |
if (response.contentAsString){ | |
var output = JSON.parse(response.contentAsString); | |
return JSON.stringify(output.data); | |
} | |
return false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment