Delphix automation using REST

  • 0
  • 1
  • Question
  • Updated 2 months ago
  • In Progress
Hi,
I am new to using REST.  I am confortable using delphix CLI to sutomate. However , can't see what is wrong with my rest program. 

Here is the code :

---------------------------------------------------------------------------------------------------------------
#!/bin/ksh

# Create API session
echo "Initiate Session "

curl -s -S -X POST -k --data @- http://10.64.148.77/resources/json/delphix/session \
-c ~/cookies.txt -H "Content-Type: application/json" <<EOF
{
 "type": "APISession",
 "version": {
 "type": "APIVersion",
 "major": 1,
 "minor": 7,
 "micro": 0
 }
}
EOF


echo "Initiated Session"

# login
curl -s -S -X POST -k --data @- http://10.64.148.77/resources/json/delphix/login \
 -b ~/cookies.txt -H "Content-Type: application/json" <<EOF
{
 "type": "LoginRequest",
 "username": "amathe01",
 "password": djsdlfjdo_23"
}
EOF


# List ENV
echo "\n\n List Env Information"
curl -S -X GET -k http://10.64.148.77/resources/json/delphix/environment \
 -b ~/cookies.txt -H "Content-Type: application/json"

---------------------------------------------------------------------------------------------------------
Problem:
------------

When executing the script it only executed the first CURL and returns to command prompt. 
However, I can execute each command from the script on the command line and get the 
expected output. What am I missing?

Here is the output :
Initiate Session
{"type":"OKResult","status":"OK","result":{"type":"APISession","version":{"type":"APIVersion","major":1,"minor":7,"micro":0},"locale":null,"client":null},"job":null,"action":null}


A second question. Is there way not to send clear test password to the login request? Delphix CLI provides an encryption mecahnism. 

Thanks in advance !

Photo of Ansamma Mathews

Ansamma Mathews

  • 292 Points 250 badge 2x thumb

Posted 2 months ago

  • 0
  • 1
Photo of Adam Bowen

Adam Bowen, Official Rep

  • 17,884 Points 10k badge 2x thumb
Start by looking at my example here:https://community.delphix.com/delphix/topics/provision-a-oracle-vdb-through-api-call

To your second question, you are using curl in your rest calls. Here is an article that speaks to how to pass passwords to curl commands: https://stackoverflow.com/questions/2594880/using-curl-with-a-username-and-password

You would also need toResearch how toUse SSL with curl If you don't want to transmit information in plaintext.

If you're just doing some ad hoc scripts for yourself,Then maybe this is worthwhile.But, if you're going to do actual enterprise automation,You should really look into using a robust programming language like Python or golang
Photo of Ansamma Mathews

Ansamma Mathews

  • 292 Points 250 badge 2x thumb
Thank you Adam ! Perfect !!