I have a Kubernetes cluster on which is deployed a replica of this image (but it's not important for the sake of the question).
Now, in Powershell I need to perform one REST request against the pod. In particular I have to send a PUT request to the endpoint http://<POD_IP>:18681/PCCIS/V1/Service/Properties/Servers passing this JSON payload:
{"servers":[{"port":"18682","address":"10.244.1.29"}]}
What I was trying to do is perform this action from within a curlimages/curl pod, just to be able to reach the pod's network. This is my attempt:
$PrizmDocPodIP="10.244.1.29"
$JsonPostBody='{"servers":[{"port":"18682","address":"10.244.1.29"}]}'
$cmd = "curl -i --header 'Content-Type: application/json' --request PUT --data '$JsonPostBody' http://$($PrizmDocPodIP):18681/PCCIS/V1/Service/Properties/Servers"
kubectl run -i --tty --rm curl --image=curlimages/curl --restart=Never "$cmd"
Unexpectedly, the command output this error:
curl: (3) nested brace in URL position 82:
curl -i --header 'Content-Type: application/json' --request PUT --data '{servers:[{port:18682,address:10.244.1.29}]}' http://10.244.1.29:18681/PCCIS/V1/Service/Properties/Servers
As you can see, the problem I have is that the string command I pass is not interpreted the right way and moreover the payload loses all the doublequotes of the JSON, that are important for the curl command to propertly work.
One another test I made is with this command (the echo is used to show what the sh command really would execute)
kubectl run -i --tty --rm curl --image=curlimages/curl --restart=Never -- sh -c "echo $cmd"
And the output is
curl -i --header Content-Type: application/json --request PUT --data {servers:[{port:18682,address:10.244.1.29}]} http://10.244.1.29:18681/PCCIS/V1/Service/Properties/Servers
Showing that the cmd Powershell variable loses its doublequotes when passed to kubectl run
What should be the right syntax to pass the $cmd command as is (preserving all its quotes and chars)?
I found the solution after some searching and trials.
First, I have to escape the double quotes in the $JsonPostBody variable.
$PrizmDocPodIP="10.244.1.29"
$JsonPostBody='{\"servers\":[{\"port\":\"18682\",\"address\":\"10.244.1.29\"}]}'
The other error is that the curlimages/curl Docker image executes the kubectl run arguments as the curl's arguments, so I don't have to use the curl command:
kubectl run -i --tty --rm curl --image=curlimages/curl --restart=Never -- -i --header 'Content-Type: application/json' --request PUT --data $JsonPostBody http://$($PrizmDocPodIP):18681/PCCIS/V1/Service/Properties/Servers
This outputs
HTTP/1.1 200 OK
[1mDate[0m: Wed, 08 Jul 2020 13:23:30 GMT
[1mConnection[0m: keep-alive
1mContent-Length[0m: 0
Related
Please advise, how to remove files inside a container using the Docker API?
I have tried to do it this way, but it doesn't work
curl --location --request POST 'http://192.168.1.55:5555/containers/{id}/exec' \
--header 'Content-Type: application/json' \
--data-raw '{
"Cmd": [
"/bin/sh",
"-c",
"'rm -rf /files/*'"
]
}'
According to the Docker API doc "To exec a command in a container, you first need to create an exec instance, then start it. These two API endpoints are wrapped up in a single command-line command, docker exec." In this way, after getting the response you must run new POST request /exec/{id}/start
I am trying to delete grafana dashboard using curl command, but it is not deleting, the below curl command I tried to delete the dashboard,
curl -XPOST -d '{"name":"mydashboard"}' http://localhost:3000/api/dashboards/db -u admin:admin -H "Content-Type: application/json"
Run the below command,
curl -k -X DELETE -u admin:admin http://localhost:3000/api/dashboards/db/dashboardslug_name
where dashboardslug_name is the name while save the dashboard and not the dashboard title displaying in the web url.
I am trying to import existing json file using HTTP API, but the 'curl' command throwing the error.
I am using the below command to import existing json file,
curl --user admin:admin "http://localhost:3000/api/dashboards/db" -X POST -H "Content-Type:application/json;charset=UTF-8" --data-binary #/u04/sys_monitor/my_Metrics.json
If i run the above command, it is throwing the error like "[{"fieldNames":["Dashboard"],"classification":"RequiredError","message":"Required"}]"
I tried to run the below command,
curl --fail --insecure --user admin:admin --request "POST" "http://localhost:3000/api/dashboards/db" --header "Content-Type: application/json" --data-binary #/u04/sys_monitor/my_Metrics.json
For the above command execution i am getting the error like,
curl: (22) The requested URL returned error: 422 Unprocessable Entity
Where i am doing wrong, kindly assist me,
The below comment is working but not updated the dashboard in grafana,
curl --user admin:admin -vvv "http://localhost:3000/api/dashboards/db" -X POST -d #My_Metrics.json -H 'Content-Type: application/json'
I'm attempting to execute the following CURL call via commandline:
curl -i -H "Content-Type:application/json" \
-u "m19389#dev.acp.co.com:qE2P/N7y1k.\(" \
-X GET -d "https://wefd.it.co.com:3905/events/com.co.mpm.dev.29160-wgdhfgd-v1/dsd/dsdfds-0-0-1-7c49768976-2g7kq"
I've added quotes around the arguments and all, and I'm definitely inclusing the curl url, so I'm not sure what's going on here. Where did I go wrong?
I am trying to call PingAccess APIs to configure my PingAccess.
I am new to using APIs to do this, and have a question.
I am trying to use CURL to the API .
curl -k -u Administrator:dummypsswd -H "X-Xsrf-Header: PingAccess" -H "Content-Type: application/json" -d '{"alias":"PLACEHOLDER_STAR_MINGLE","fileData": [[System.IO.File]::ReadAllBytes("C:\test.pfx")],"password": "1234"}' https://localhost:9000/pa-admin-api/v1/keyPairs/import -v
When I run this I get the following error.
I still dont know why am I unauthorized. Any help is appreciated.
When you have special characters in your password you'll need to enclose the username/password tuple in double quotes:
curl -k -u "Administrator:dummypsswdwithspecialcharslike&&" -H "X-Xsrf-Header: PingAccess" -H "Content-Type: application/json" -d '{"alias":"PLACEHOLDER_STAR_MINGLE","fileData": [[System.IO.File]::ReadAllBytes("C:\test.pfx")],"password": "1234"}' https://localhost:9000/pa-admin-api/v1/keyPairs/import -v