curl command in scala to fletch password from vault - scala

i have curl command as below
curl \
--request POST --insecure \
--data '{"role_id":"xxxx-xx-xx-xx-xxxx","secret_id":"xxx-xx-xx-xx-xxxx"}' \
https://vault.us-west-2.shared-lab.aws.hcom/v1/auth/approle/login
i have transformed this code as shown below
val jsonBody = new JSONObject()
jsonBody.put("role_id", "xxxx-xx-xx-xx-xxxx")
jsonBody.put("secret_id", "xxx-xx-xx-xx-xxxx")
println("json" + jsonBody)
val tokenCmd = Seq("curl", "-H", s"--request POST --insecure --data ", "-d", s"$jsonBody","https://vault.us-west-2.shared-lab.aws.hcom/v1/auth/approle/login")
val tokenExtractor = tokenCmd.!!
println("y is " +tokenExtractor)
val VAULT_TOKEN =tokenExtractor.substring(173,199)
println("token "+ VAULT_TOKEN)
val cmd2 = Seq("curl", "-H", s"X-Vault-Token: ${VAULT_TOKEN}","https://vault.us-west-2.shared-lab.aws.hcom/v1/xxx/xxx/xxx")
the code works locally, but to get when ran in another server, its failing for the below reason.
App > curl failed to verify the legitimacy of the server and therefore could not
App > establish a secure connection to it. To learn more about this situation and
App > how to fix it, please visit the web page mentioned above.
App > 21/09/06 18:58:57 main ERROR SparkSubmit$$anon$2: Exception thrown on spark-submit: Nonzero exit value: 60
App > java.lang.RuntimeException: Nonzero exit value: 60
i am ready to use an insecure --insecure, but able to apply , is their any config i need to update. any help is appreciated.

Related

CircleCI job is failing, help troubleshoot

PUBLIC_DNS=$(aws ec2 describe-instances --region ${AWS_DEFAULT_REGION} --filters 'Name=tag:Name,Values=udapeople-backend-ec2-*' --query "Reservations[*].Instances[0].PublicDnsName" --output text)
echo ${PUBLIC_DNS}
curl -H "Content-Type: text/plain" \
-H "token: ${CIRCLE_WORKFLOW_ID}" \
--request PUT \
--data ${PUBLIC_DNS} \
https://api.memstash.io/values/public_dns
curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information
Exited with code exit status 2
CircleCI received exit code 2
your error isn't with Circle CI but with your curl command. The error message is saying it doesn't have a URL to which to PUT. I do see that you included a URL in your curl command, so maybe the problem is in your line endings. Try removing the line endings and run your circle CI job again. You can also try running the command from your local command line.
This is because memstash.io is not working as a website or webservice, there is no issue in your code , memstash is working as a memory-cache for CD jobs so you can find another CD caching service or you have a good option to use circle ci caching itself , try to search for circleCI docs

Passing parameters in body in POST API Call to Openstack Nova

I am trying to stop a running server instance on Openstack Nova. I am using the following API as a reference
https://developer.openstack.org/api-ref/compute/#stop-server-os-stop-action
The following is my code snippet
import openstack.config
self.cloud_region = openstack.config.OpenStackConfig().get_one('adminproject')
self.session = self.cloud_region.get_session_client('compute')
I am able to make GET requests to the server
response = self.session.get(url)
But when i try to make POST requests, I am getting errors. This is how I am trying to do it
url = "/servers/" + vm_id + "/action
body = {"os-stop":"null"}
reponse = self.session.post(url, {'os-stop' : 'null'})
TypeError: post() takes exactly 2 arguments (3 given)
I have also tried
reponse = self.session.post(url, body=body)
which gives me an error
TypeError: request() got an unexpected keyword argument 'body'
When i do it via the nova client and enable the debug mode, this is what i get
curl -g -i -X POST http://IP:PORT/v2.1/12bf80bc27cf4fdc87a2ce2cb0619159/servers/93bc82d4-7a3b-4f67-bc6e-dfb2553a57fc/action -H "Accept: application/json" -H "Content-Type: application/json" -H "User-Agent: python-novaclient" -H "X-Auth-Token: {SHA1}447e97116c71efcff1a02f4d7fdf8d76a4490d9d" -d '{"os-stop": null}'
It would be great if someone can help in finding out how to emulate the above request.
TIA.

Execute curl command in scala to get shipping charges from easypost API

I am trying execute a curl command in scala. The curl command fetched the shipping charges from easypost API. Below is the code I am using :
import sys.process._
val data="curl -X POST https://api.easypost.com/v2/shipments -u <Easypost Test API Key>: -d 'shipment[to_address][zip]=90277' -d 'shipment[from_address][zip]=94104' -d 'shipment[parcel][length]=20.2' -d 'shipment[parcel][width]=10.9' -d 'shipment[parcel][height]=5' -d 'shipment[parcel][weight]=65.9'".!!
println("Shipping data is "+data)
I am getting :
Shipping data is {"error":{"code":"SHIPMENT.INVALID_PARAMS","message":"Unable to create shipment, one or more parameters were invalid.","errors":[]}}
But in terminal it is responding like :
{"created_at":"2017-03-03T05:31:03Z","is_return":false,"messages":[],"mode":"test","options":{"currency":"USD","label_date":null,"date_advance":0},"reference":null,"status":"unknown","tracking_code":null,"updated_at":"2017-03-03T05:31:03Z","batch_id":null,"batch_status":null,"batch_message":null,"customs_info":null,"from_address":{"id":"adr_382aaa644ccb4ecfb3f14db65275dc47","object":"Address","created_at":"2017-03-03T05:31:03Z","updated_at":"2017-03-03T05:31:03Z","name":null,"company":null,"street1":null,"street2":null,"city":null,"state":null,"zip":"94104","country":"US","phone":null,"email":null,"mode":"test","carrier_facility":null,"residential":null,"federal_tax_id":null,"state_tax_id":null,"verifications":{}},"insurance":null,"order_id":null,"parcel":{"id":"prcl_adf352eee75d43339279f959b8cd1118","object":"Parcel","created_at":"2017-03-03T05:31:03Z","updated_at":"2017-03-03T05:31:03Z","length":20.2,"width":10.9,"height":5.0,"predefined_package":null,"weight":65.9,"mode":"test"},"postage_label":null,"rates":[{"id":"rate_9799f33dbc99420abeba4101d6a0d31f","object":"Rate","created_at":"2017-03-03T05:31:03Z","updated_at":"2017-03-03T05:31:03Z","mode":"test","service":"Express","carrier":"USPS","rate":"37.08","currency":"USD","retail_rate":"41.80","retail_currency":"USD","list_rate":"37.08","list_currency":"USD","delivery_days":null,"delivery_date":null,"delivery_date_guaranteed":false,"est_delivery_days":null,"shipment_id":"shp_54916a9085114979a300c0ba7b10efd7","carrier_account_id":"ca_bba7f2862b2e4a6aa682dcf5eeb0de38"},{"id":"rate_df1211dd22ab4aefa83cc34e206acb9c","object":"Rate","created_at":"2017-03-03T05:31:03Z","updated_at":"2017-03-03T05:31:03Z","mode":"test","service":"Priority","carrier":"USPS","rate":"8.91","currency":"USD","retail_rate":"11.95","retail_currency":"USD","list_rate":"9.19","list_currency":"USD","delivery_days":2,"delivery_date":null,"delivery_date_guaranteed":false,"est_delivery_days":2,"shipment_id":"shp_54916a9085114979a300c0ba7b10efd7","carrier_account_id":"ca_bba7f2862b2e4a6aa682dcf5eeb0de38"},{"id":"rate_37f9ba8a68304222b02c15019a02918a","object":"Rate","created_at":"2017-03-03T05:31:03Z","updated_at":"2017-03-03T05:31:03Z","mode":"test","service":"ParcelSelect","carrier":"USPS","rate":"9.19","currency":"USD","retail_rate":"9.19","retail_currency":"USD","list_rate":"9.19","list_currency":"USD","delivery_days":5,"delivery_date":null,"delivery_date_guaranteed":false,"est_delivery_days":5,"shipment_id":"shp_54916a9085114979a300c0ba7b10efd7","carrier_account_id":"ca_bba7f2862b2e4a6aa682dcf5eeb0de38"}],"refund_status":null,"scan_form":null,"selected_rate":null,"tracker":null,"to_address":{"id":"adr_9aa339f8acd244059e5ffb775c541dba","object":"Address","created_at":"2017-03-03T05:31:03Z","updated_at":"2017-03-03T05:31:03Z","name":null,"company":null,"street1":null,"street2":null,"city":null,"state":null,"zip":"90277","country":"US","phone":null,"email":null,"mode":"test","carrier_facility":null,"residential":null,"federal_tax_id":null,"state_tax_id":null,"verifications":{}},"usps_zone":4,"return_address":{"id":"adr_382aaa644ccb4ecfb3f14db65275dc47","object":"Address","created_at":"2017-03-03T05:31:03Z","updated_at":"2017-03-03T05:31:03Z","name":null,"company":null,"street1":null,"street2":null,"city":null,"state":null,"zip":"94104","country":"US","phone":null,"email":null,"mode":"test","carrier_facility":null,"residential":null,"federal_tax_id":null,"state_tax_id":null,"verifications":{}},"buyer_address":{"id":"adr_9aa339f8acd244059e5ffb775c541dba","object":"Address","created_at":"2017-03-03T05:31:03Z","updated_at":"2017-03-03T05:31:03Z","name":null,"company":null,"street1":null,"street2":null,"city":null,"state":null,"zip":"90277","country":"US","phone":null,"email":null,"mode":"test","carrier_facility":null,"residential":null,"federal_tax_id":null,"state_tax_id":null,"verifications":{}},"forms":[],"fees":[],"id":"shp_54916a9085114979a300c0ba7b10efd7","object":"Shipment"}
Am I doing something wrong here ? Please suggest.
It looks like curl is successfully contacting the service, but it is rejecting your request.
Are you sure you are using the exact same arguments on the command-line as you are in the scala version? The trailing ":" on the API key looks suspicious to me.
I wonder if this is a shell escaping problem. Maybe try using the Seq[String] form of ProcessBuilder, to avoid any shell escaping?
import sys.process._
val data = List("curl", "-X", "POST", "https://api.easypost.com/v2/shipments", "-u", "<Easypost Test API Key>:", "-d", "shipment[to_address][zip]=90277", "-d", "shipment[from_address][zip]=94104", "-d", "shipment[parcel][length]=20.2", "-d", "shipment[parcel][width]=10.9", "-d", "shipment[parcel][height]=5", "-d", "shipment[parcel][weight]=65.9").!!
println("Shipping data is " + data)

Mashape multipart-form POST request

I have a POST method in my API which uses multipart encoded form data. I have set up the correct header and data settings so that the mashape web interface generated the following curl:
curl -X POST --include 'https://sslavov-text-analytics-v1.p.mashape.com/news' \
-H 'Authorization: Basic ***********' \
-H 'X-Mashape-Key: ************' \
-H 'Content-Type: multipart/form-data' \
-F 'file=#sample.docx' \
-F 'meta={"documentType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"};type=application/json'
Basically i'm trying to upload a file with a simple paragraph of text for processing. The curious part is that when I run this exact curl in a bash script, everything works smoothly, but when I try to run it through mashape, it says either 400 Bad Request or 500 Internal Server Error
In my particular case, these errors are generated when I don't pass correct form or headers. So my question is: Is there an error in the curl syntax or should I keep looking for the error on server side?
EDIT: I figured out what the problem was. -F 'file=#sample.docx' was passed before -F 'meta....' and that was causing the 500 Internal Server Error So now the question is: Is there any way to specifically arrange the order of the form fields (because mashape rearranges them aplhabetically)?

Https Error in Postman when Send push notification via Rest

I'm fairly new To Parse with Rest Api
I wanna test samples in Their Webistes's ( Here ) in Postman But every time I Post it gives me following Authentication error :
I Wanna test following code in Postman ( see origin here )
curl -X POST \
-H "X-Parse-Application-Id: 0VoIZO8cgmnyfiuklLLkKkxOX7r" \
-H "X-Parse-REST-API-Key: UjU5eb5zjic75mPZVdHExYqnneT" \
-H "Content-Type: application/json" \
-d '{
"deviceType": "ios",
"deviceToken": "0123456789abcdef0123456789cdef0123456789abcdef",
"channels": [
""
]
}' \
https://api.parse.com/1/installations
How Can I resolve this issue ? What is that ? And What is required ?
You are reqeuesting GET request and api doc says its POST request.
1) Enter correct url and select POST request method. Add required headers as per the doc.
2) Enter raw JSON data in your request body.
3) You will receive your output. Since api key and application id is not valid so that I received unauthorized error.