Tortoise SVN Post-Commit Hook Windows - batch-file

I'm working on a simple slack integration for SVN projects via a client side post-commit hook in Windows Tortoise SVN using curl to send JSON. I would like to post some basic information, ideally revision number and comment when a commit is made. I added a post-commit client side hook, that executes a postcommit.bat file that succeeds in sending my slack channel a message. What I can't get working is including the passed in variables from tortoise. According to tortoise a SVN client side hook post-commit will include the following argument PATH DEPTH MESSAGEFILE REVISION ERROR CWD https://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-dug-settings.html
Here is my working code, that sends a static string (not including message/revision to my slack channel):
C:\p\curl -H "Content-Type: application/json" -X POST https://hooks.slack.com/services/MYSECRETSERVICE -d "{\"text\":\"Test message\"}"
I would like to do something like this, but the following code does not, it simply posts "RevMessage", or in other words the parameters are not properly passed:
C:\p\curl -H "Content-Type: application/json" -X POST https://hooks.slack.com/services/MYSECRETSERVICE -d "{\"text\":\"Rev%REVISION%Message%MESSAGE%\"}"

Okay, this may have been so specific (judging by view count) that I was bound to answer it myself, lol. Anyway, perhaps someone else will find this useful, here is what ended up working for me. First variables need to be set from arguments, then they can be referenced as shown:
set tsvnPath=%1
set tsvnDepth=%2
set tsvnMsgFile=%3
set /p THEMSG=<%3
set tsvnRevision=%4
set tsvnError=%5
set tsvnCwd=%6
C:\p\curl -H "Content-Type: application/json" -X POST https://hooks.slack.com/services/MYSECRET -d "{\"text\":\"MSG %THEMSG% REV %tsvnRevision%\"}"

Related

Bash: works at command line but getting 'curl: (1) Protocol ""https" not supported or disabled in libcurl' when using in a script

Got stuck with the situation that a curl request works fine with the command line but does not work at a script giving weird errors. Here is the part of the script:
#we already got the $token
#vars defining curl parameters
dc="NA EU AU SEA JP"
curl_url='https://example.com/api/config/v1/'
curl_request='alertingProfiles?'
curl_properties='tenant=all&stage=prd&cluster='
curl_auth='"Authorization: Bearer '"$token"'"'
for k in $dc; do
# Download the json for each DC using the curl request
curl_combined=\""$curl_url$curl_request$curl_properties$k"\"; echo "$curl_combined"
curlCMD=( -vv --location --request GET "$curl_combined" -H "$curl_auth" -o \""$k.json"\")
echo "${curlCMD[#]}"
curl "${curlCMD[#]}"
done
When I run this in a script I see the following output:
First, the output from the first echo command
"https://example.com/api/config/v1/alertingProfiles?tenant=all&stage=prd&cluster=NA"
Then, the output from the second echo command which is what curl should take as a parameter, I've skipped the bearer token, but trust me, it is not a problem here.
-vv --location --request GET "https://example.com/api/config/v1/alertingProfiles?tenant=all&stage=prd&cluster=NA" -H "Authorization: Bearer " -o "NA.json"
And I am getting following output
Note: Unnecessary use of -X or --request, GET is already inferred.
* Protocol ""https" not supported or disabled in libcurl
* Closing connection -1
curl: (1) Protocol ""https" not supported or disabled in libcurl
Please note two double quotes in the message above in front of https.
If I simply copy/paste the above second echo output in the command line right after curl and execute, it works as expected and downloads JSON in the file.
If I remove " from curl_combined var, the request is sent without double quotes and now I am getting the message curl: (56) Unexpected EOF from the script.
If I copy/paste the second echo output (without double quotes), supply it to curl, and execute from the command line, I am getting 403 message until I put double or single quotes around the https request.
In short - it seems that double quotes around the https request is necessary but for some reason, curl does not take it.
So what went wrong here? I don't mind even to write the constructed URL in a file and read from it or use herestring if it helps, but want to know what exactly went wrong here.
Thanks.
P.S. Removing --location or --request GET or both does not change the outcome.
The script is using passing the "${curlCMD[#]}" array as parameter to curl. This approach will handle the correct expansion of the url, regardless of any special characters in it. There is no need to wrap the curl_combined with additional quotes using the \" construct.
Suggesting replacing setting curl_combined with:
curl_combined="$curl_url$curl_request$curl_properties$k"
echo "$curl_combined"
This solution works replacing curl request with array to the following
curl -vv \
--location \
--request GET \
"$curl_combined" \
--header "Authorization: Bearer ${token}" \
-o "$k.json"
But it is ugly, let's say politely...

Unable to submit Job in Flink using post request via curl request (Request did not match...)

I was trying to send a post request to Flink Job manager running on Kubernetes cluster. While sending post request of /jar/run for a class which doesn't need any command line arguments, it works fine. But while trying to submit a different class in the same jar which requires command line arguments gives following error. -:
{"errors":["Request did not match expected format JarRunRequestBody."]}'
However, while passing command line arguments and submitting job directly like following works -:
./flink run -m localhost:30287 -c com.class.name ~/path/to/jar/1.0-1.0-SNAPSHOT.jar --bootstrap.servers izac-cp-kafka:9092 --group.id test --topic bank_transaction --schema.registry http://mysr-schema-registry:8081 --CepJson """{\"keyId\": \"customer_id\",\"pattern\": [{\"patternName\": \"p1\",\"simpleCondition\":{\"columnName\": \"amount\",\"operator\": \">\",\"value\": \"50\",\"dataType\": \"Int\"}},{\"patternName\":\"p2\",\"simpleCondition\":{\"columnName\":\"amount\",\"operator\":\">\",\"value\":\"30\",\"dataType\":\"Int\"}}],\"connector\":[{\"name\":\"begin\",\"connectorType\":\"next\",\"start\":\"p1\",\"end\":\"p2\"}]}"""
To convert above command to a flink REST based post request I did the following -:
curl -k -v -X POST -H "Content-Type: application/json" --data '{ "entryClass":"com.class.name", "programArgsList": [ "--bootstrap.servers izac-cp-kafka:9092", "--group.id test", "--topic bank_transaction", "--schema.registry http://mysr-schema-registry:8081", "--CepJson """{\"keyId\": \"customer_id\",\"pattern\": [{\"patternName\": \"p1\",\"simpleCondition\":{\"columnName\": \"amount\",\"operator\": \">\",\"value\": \"50\",\"dataType\": \"Int\"}},{\"patternName\":\"p2\",\"simpleCondition\":{\"columnName\":\"amount\",\"operator\":\">\",\"value\":\"30\",\"dataType\":\"Int\"}}],\"connector\":[{\"name\":\"begin\",\"connectorType\":\"next\",\"start\":\"p1\",\"end\":\"p2\"}]}""""]}' http://localhost:30287/jars/2a788e33-c92d-47c4-84af-31e3dff28666_1.0-1.0-SNAPSHOT.jar/run
However, this gave the error as mentioned earlier. I just wanted to convert the above command line job submission to a rest api based submission to flink cluster.
Note -: The post request is for a cluster of flink which already contains the required Jar. I only want to submit a job using a particular class.
I don't think that curl accepts """ as a string interpolation the way scala does so it won't send correct CepJson parameter for sure, so I would start with changing that.
I changed the above curl request to the following and it worked -:
curl -k -v -X POST -H "Content-Type: application/json" --data '{ "entryClass":"com.class.name", "programArgsList": [ "--bootstrap.servers", "izac-cp-kafka:9092", "--group.id"," test", "--topic","bank_transaction", "--schema.registry", "http://mysr-schema-registry:8081", "--CepJson", "{\"keyId\": \"customer_id\",\"pattern\": [{\"patternName\": \"p1\",\"simpleCondition\":{\"columnName\": \"amount\",\"operator\": \">\",\"value\": \"50\",\"dataType\": \"Int\"}},{\"patternName\":\"p2\",\"simpleCondition\":{\"columnName\":\"amount\",\"operator\":\">\",\"value\":\"30\",\"dataType\":\"Int\"}}],\"connector\":[{\"name\":\"begin\",\"connectorType\":\"next\",\"start\":\"p1\",\"end\":\"p2\"}]}"]}' http://localhost:30287/jars/2a788e33-c92d-47c4-84af-31e3dff28666_1.0-1.0-SNAPSHOT.jar/run

Sending empty string value for a custom request header using cURL

I am trying to send a HTTP POST custom request header (X-Privet-Token) with value set to "" using cURL on a Linux machine. Following is my command:
curl -k -sI POST -H "X-Privet-Token:" -H "Content-Type: application/json" --trace-ascii --data "action=start&user=xyz#gmail.com" https://127.0.0.1/privet/register
I would like to send an empty string to the server.
Am I missing something?
You can use the following syntax to set a custom header with an empty value
curl -H "X-custom-header;" <some host>
From the man page:
man curl
...
-H, --header <header>
...
If you send the custom header with no-value then its header must be termi-
nated with a semicolon, such as -H "X-Custom-Header;" to send "X-Custom-Header:".
...
I know it is an old question, but I think it is worth to answer it.
I faced a similar issue when calling the privet/info API call in a Java client app, I realized the header was not sent when it was empty. If you want to set an empty header, try to use \"\" (that's what privet documentation states for /privet/info API call):
curl -k -sI POST -H "x-privet-token: \"\"" -H "Content-Type: application/json" --trace-ascii --data "action=start&user=xyz#gmail.com" https://127.0.0.1/privet/register
On the other hand, the privet/register API call requires a valid x-privet-token. Leaving the x-privet-token header empty, 'curl' may be ommiting it.
Having said that, the error you are getting occurs when the endpoint is not advertising /privet/register API, probably because it's already registered. You can check the APIs that the device is exposing examining the /privet/info response.

cURL Cloudant attachment example please

Please forgive me for the potentially basic question but I am a z/OS person trying to learn cURL and Cloudant. I have gotten the following example to work to add a record to a database (using DOS from Windows) :
curl -X POST -b /tmp/cloudant.cookie -H "Content-Type: application/json" -d "{\"_id\":\"2\",\"empName\":\"John Doe\",\"phone\":\"646-598-4133\",\"age\":\"28\"}" --url https://xxxxxxxxxx-bluemix.cloudant.com/rcdb
Now I would like to add a _attachment image1.jpg dile to that record...
Could anyone please tell me what the syntax on windows would be...trying a few combinations but nothing so far works.
To add an attachment follow the instructions in the Cloudant documentation at https://docs.cloudant.com/attachments.html
Example:
Assuming you have already created a document with ID "2" and revision number "1-954695fb9642f02975d76b959d0b5e98" in database rcdb, run the following command:
curl -X PUT -H "Content-Type: image/jpeg" --data-binary "#image1.jpg" --url https://xxxxxxxxxx-bluemix.cloudant.com/$DATABASE/$DOCUMENT_ID/$ATTACHMENT?rev=$REV
replacing $DATABASE with rcdb, $DOCUMENT_ID with 2, $REV with 1-954695fb9642f02975d76b959d0b5e98 and $ATTACHMENT with the desired attachment property name, e.g. mypic.

Send a POST request with some data, including a file, using Curl

How can I include a file in a curl request form my working directory?
Below I've got a POST request that includes data for "first_name" and for "last_name", but now I need to add in the input for file. Theres examples out there where someone is ONLY sending a file along, but I'm trying to send 1 or more files, and other data.
curl
-H "Content-Type: application/json"
-d '{ first_name: "Donny", last_name: "P", my_file: ???? }'
https://sender.blockspring.com/api/blocks/319bfef4aad7f3477745048a2da3ae6a?api_key=2e0ef0c216078d60630d1321e67b243a
This can be only done with a multipart.
Manually building a multipart may be complex, so curl has a built-in -F option.
curl localhost:8000 -F "my_file=#file.ext" -F "name=daniel;last=P" -v
from man curl
-F, --form
(HTTP) This lets curl emulate a filled-in form in which a user has pressed the submit button. This causes curl to POST
data using the Content-Type multipart/form-data according to RFC 2388. This enables uploading of binary files etc.
To
force the 'content' part to be a file, prefix the file name with an # sign. To just get the content part from a file,
prefix the file name with the symbol <. The difference between # and < is then that # makes a file get attached in the
post as a file upload, while the < makes a text field and just get the contents for that text field from a file.

Resources