Created
August 13, 2018 18:45
-
-
Save stobias123/d1759e0d61e58ea94e4994c98566ab4c to your computer and use it in GitHub Desktop.
scrubbed sriptrunner
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
import groovyx.net.http.* | |
import org.apache.log4j.Logger | |
import org.apache.log4j.Level | |
import groovy.json.JsonBuilder | |
import groovy.json.StreamingJsonBuilder; | |
RESTClient myClient | |
myClient = new RESTClient("https://tower_hostname.com/api/v2/authtoken") | |
myClient.headers = composeRequestHeaders() | |
private Map<String, String> composeRequestHeaders() { | |
Map<String, String> headerMap = new HashMap<>() | |
headerMap.'Content-Type' = 'application/json' | |
headerMap.'Accept' = 'application/json' | |
return headerMap | |
} | |
def requestBody = [ | |
username : "username", | |
password : "password", | |
] | |
def json = new JsonBuilder( requestBody ) | |
log.error json | |
HttpResponseDecorator responseToPost = | |
(HttpResponseDecorator) myClient.post(path: "/", body: json, requestContentType: org.apache.http.entity.ContentType.APPLICATION_JSON) | |
if (responseToPost.status == 201) { | |
def actualResourceObject = responseToPost.data | |
log.error actualResourceObject | |
} | |
log.error responseToPost.getStatus() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment