I'm trying to perform some rest commands against delphix from Jenkins pipelines. I have a groovy script trying to get a session, then login token. This is on a windows host. From the bash examples, it looks like its adding to a cookie with each curl call.
Here's the code:
def delphix_url = "172.31.79.14"def urlString = "http://${delphix_url}/resources/json/delphix";
def login_params = "{\"type\"=\"LoginRequest\"\n"
login_params += "\"username\"=\"delphix_admin\"\n"
login_params += "\"password\"=\"delphix\"\n}"
def api_params = "{\"type\": \"APISession\",\n"
api_params += "\"version\": {\n"
api_params += "\"type\": \"APIVersion\",\n"
api_params += "\"major\": 1,\n"
api_params += "\"minor\": 7,\n"
api_params += "\"micro\": 0}\n"
api_params += "}"
// Do the Session
separator()
println "API Params"
println api_params
URLConnection con = "${urlString}/session".toURL().openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestProperty("Content-Type", "application/json");
con.outputStream.withWriter { writer ->
writer << api_params
}
def postRC = con.getResponseCode()
def cresp = con.getHeaderField("Cookies")
//def response = con.inputStream.withReader { Reader reader -> reader.text }
def response = con.getInputStream().getText()
println "URL: " + "${urlString}/session"
println "Result: " + postRC
println "Cookie: " + cresp
println "Response: " + response
def cookie = "user=mary17; domain=airtravelbargains.com; path=/autos"
// Do the Login
separator()
println "Login Params"
println login_params
con = "${urlString}/login".toURL().openConnection();
//con.setRequestProperty("Cookie", cookie)
con.setUseCaches(true)
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestProperty("Content-Type", "application/json");
con.outputStream.withWriter { writer ->
writer << login_params
}
postRC = con.getResponseCode()
cresp = con.getHeaderField("Cookies")
//def response = con.inputStream.withReader { Reader reader -> reader.text }
response = con.getInputStream().getText()
println "URL: " + "${urlString}/login"
println "Result: " + postRC
println "Cookie: " + cresp
println "Response: " + response
println response
Here's the output. You can see, the cookie parameter is empty after getting a 200 on session.
API Params {"type": "APISession", "version": { "type": "APIVersion", "major": 1, "minor": 7, "micro": 0} } URL: http://172.31.79.14/resources/json/delphix/session Result: 200 Cookie: null Response: {"type":"OKResult","status":"OK","result":{"type":"APISession","version":{"type":"APIVersion","major":1,"minor":7,"micro":0},"locale":null,"client":null},"job":null,"action":null} #--------------------------------------------------------------------------------# Login Params {"type"="LoginRequest" "username"="delphix_admin" "password"="delphix" } URL: http://172.31.79.14/resources/json/delphix/login Result: 200 Cookie: null Response: {"type":"ErrorResult","status":"ERROR","error":{"type":"APIError","details":"No API session has been established.","action":"Create an API session by calling /resources/json/delphix/session.","id":"exception.webservices.session.nosession","commandOutput":null,"diagnoses":null}} {"type":"ErrorResult","status":"ERROR","error":{"type":"APIError","details":"No API session has been established.","action":"Create an API session by calling /resources/json/delphix/session.","id":"exception.webservices.session.nosession","commandOutput":null,"diagnoses":null}}