Unable to upload html file from Jenkins to Slack channel - jenkins-pipeline

I am sending build start, success and failure notification to slack channel which is working fine only upload file is not working. I am using same token for sending notifications to slack channel which works fine. Not sure how to pass the token in upload file slack api.
I have used below in my pipeline script.
sh 'curl --request POST \
--url https://slack.com/api/files.upload \
--form token=$SLACK_CREDENTIAL_ID \
--form channels=channel_name \
--form file=#newman/Sanity.html'
Getting error: {"ok":false,"error":"not_authed"}
How to pass token here? as its not reading the token

The problem was the bot key didn't have rights to upload the file. Once I used the bot key which has upload rights it worked.

Related

How to get bitbucket OAUTH token via bash script?

I am attempting to get an OAUTH token for bitbucket via a bash script.
At the moment, I'm able to use the following URL:
https://bitbucket.org/site/oauth2/authorize?client_id={key}&response_type=token
I simply visit this via a web browser and hit authenticate, I am then redirected to the callback website, And I can see the token in the URL. For example, if my callback url was stackoverflow.com, My url bar would now contain stackoverflow.com/#access_token=XYZ
What I need to do, is figure out how to hit this url but get this access token in a bash script rather than from a URL.
Relevant doc: https://bitbucket.org/site/oauth2/authorize?client_id=kdBELaEX6HkUexPMRS&response_type=token
Using curl (can be used inside your bash script)
curl -X POST https://bitbucket.org/site/oauth2/access_token \
-d grant_type=client_credentials \
-u key:secret

gcloud auth print-access-token gives permission denied error

I have a shell script trying to download some secrets from secret manager inside dataproc cluster.
GetAuthJson() {
authjson=$(curl "https://secretmanager.googleapis.com/v1/projects/$PROJECT_ID/secrets/$AUTH_JSON/versions/1:access" \
--request "GET" \
--header "authorization: Bearer $(gcloud auth print-access-token)" \
--header "content-type: application/json")
if [ $? -ne 0 ]; then
Error "Unable to extract the $PIPENAME Auth json details from GCP Secret Manager"
fi
echo $authjson | grep -o '"data": "[^"]*' | grep -o '[^"]*$' >$BASE_DIR/encodedauth.json
if [ $? -ne 0 ]; then
Error "Unable to save the $PIPENAME auth.json server secret to auth.json"
fi
auth_json=$(base64 -d $BASE_DIR/encodedauth.json)
base64 -d $BASE_DIR/encodedauth.json >/etc/secrets/auth.json
if [ $? -ne 0 ]; then
Error "Unable to decode the $PIPENAME auth.json server secret"
fi
Log "auth.json secret extraction done"
}
when i run this curl it generates an error
authjson='{
"error": {
"code": 403,
"message": "Permission '\''secretmanager.versions.access'\'' denied for resource '\''projects/**-**-dev/secrets/**_AUTH_JSON/versions/1'\'' (or it may not exist).",
"status": "PERMISSION_DENIED"
}
}'
the same curl with same service account is working in local meachine. and more over if i copy the CURL from local and run it in dataproc cluster it works as well.
But the curl generated from dataproc fails in local .
whats more weird is if i run gcloud auth print-access-token separately and paste it in curl command it works in both meachine.
so my question is why gcloud auth print-access-token generated as part of curl in dataproc cluster is not working ?
It would be useful if you could capture the value of the curl command or, at least the value of gcloud auth print-access-token that's failing in the script.
I suspect (I'm unfamiliar with Dataproc) that the Dataproc instance does not have gcloud installed and the gcloud auth print-access-token is failing.
If the instance does have gcloud installed, since it's running then it must have a Service Account and so should permit authenticating. There may (!?) be a more nuanced issue with getting an access token as a Dataproc instance, unclear.
Please consider using either gcloud secrets versions access directly or one of Google's client libraries to access the secret.
You're making the process more complex than it need be by curl'ing the endpoint; you're having to use gcloud anyway to get the auth token.
The issue was i ran the script as sudo user. When i ran normally it worked.

Telegram example of how to use CURL for windows 10 to message myself with a bot

I found the following curl example to use a telegram bot to message a user. But that is written in PHP.
Is there an example of how to use the curl command in windows 10 command prompt to send a message to myself in telegram messenger?
You haven't mentioned the PHP code, but using CURL you can simply call:
curl https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/sendMessage?chat_id=1234&text=hi
Replace 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11 with your own bot token and 1234 with your id. Don't forget to start the bot before messaging yourself.
Those who landed here due to above method is not working anymore -> you can use curl POST request like the following:
curl -s -o /dev/null -X POST -H "Content-Type: application/json" -d "{\"chat_id\": \"-100XXXXXXXXXX\", \"text\": \"test_message\", \"disable_notification\": false}" https://api.telegram.org/bot{API_TOKEN}/sendMessage
Where
-s - Silent mode,
-o /dev/null - redirect result output to nowhere, in case where the command is not working remove the argument to find possible cause,
disable_notification: false - send the message silently without telegram notification.
For those who really likes .bat/.sh scripts there is an option to put the command into a .bat/.sh script, replace test_message with %~1/$1 placeholders respectively and execute the script with message argument like:
. ./sendMessage.sh "Specific message having spaces"
or
. ./sendMessage.sh singleWordWithoutSpaces

get post response using curl and send it laravel api

i am new to curl and i started using it, so i have a situation where i have to post using curl to a url and get json response back, everything works fine upto this. So what i wanted to do is have this json response send to a laravel api which in turn parses out and saves to database. this is curl script i use
curl -X POST \
-H "Authorization: Basic Sjg2eFZzdVFkOVFUMTlScEd0==" \
-d "grant_type=client_credentials" \
--cert /etc/letsencrypt/live/www.sample.com/fullchain.pem \
--key /etc/letsencrypt/live/www.sample.com/privkey.pem \
https://connect.innovative.com/auth/token
i am not sure if curl can save the response directly to mysql and also how can i setup a scheduling the above script to run every 2 hours in ubuntu?
i figured it out by creating bash script and storing it to variable and then subsequent post request to api, also did a crob job and it worked like charm

curl pull request error - fork_collab Fork collab can't be granted by someone without permission

I'm trying to automate github pull requests via bash script, specifically raising pull requests for forked branches. I've successfully done it for private repos, however it doesn't seem to work for public repos (see code below):
curl -H "Authorization: bearer <accesstoken>" -d '{"title":"SOMETITLE","base":"master","head":"'"someuser"':'"someForkedBranch"'","body":"some words to fill body."}' https://api.github.com/repos/<user-name>/<repo-name>/pulls
Any help would be appreciated.
If this is for creating a PR, you would need a -X POST somewhere in your curl command, in order to POST the query for a new PR:
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/octocat/hello-world/pulls \
-d '{"head":"head","base":"base"}'
Make sure also to use the right oauth/PAT or SAML SSO:
curl -v -H "Authorization: token TOKEN" -X POST ...
Those token have just seen a new format update (Apr. 2021) so you might need to regenerate one.

Resources