How to disable the Branch Policies in Azure DevOps using REST API? - azure

I am trying to disable and again re-enable the branch policy created for a branch using Azure DevOps REST API.
The Branch Policy that I have manually created:
Using CURL I was able to get the list of Branch Policies that has been created in the repository.
curl --url "https://dev.azure.com/{ORG}/{PROJ}/_apis/policy/configurations?api-version=6.0" --user "username:password" --request GET --header "Accept: application/json"
Output:
{
"count":1,
"value":[
{
"createdBy":{
"displayName":"Akshay B",
"url":"XXXX",
"_links":{
"avatar":{
"href":"XXXX"
}
},
"id":"XXXX-XXXX-XXXX-XXXX-e0fdec2c1636",
"uniqueName":"XXXX#XXXX.com",
"imageUrl":"XXXX",
"descriptor":"XXXX"
},
"createdDate":"2021-08-30T12:24:43.0238821Z",
"isEnabled":true,
"isBlocking":true,
"isDeleted":false,
"settings":{
"minimumApproverCount":2,
"creatorVoteCounts":false,
"allowDownvotes":false,
"resetOnSourcePush":false,
"requireVoteOnLastIteration":false,
"resetRejectionsOnSourcePush":false,
"blockLastPusherVote":false,
"scope":[
{
"refName":"refs/heads/master",
"matchKind":"Exact",
"repositoryId":"XXXX-XXXX-XXXX-XXXX-cd2a5c3167b3"
}
]
},
"isEnterpriseManaged":false,
"_links":{
"self":{
"href":"XXXX"
},
"policyType":{
"href":"XXXX"
}
},
"revision":1,
"id":2,
"url":"XXXX",
"type":{
"id":"XXXX-XXXX-XXXX-XXXX-4906e5d171dd",
"url":"XXXX",
"displayName":"Minimum number of reviewers"
}
}
]
}
Now I am trying to disable the policy created above using the below CURL command:
curl --url "https://dev.azure.com/{ORG}/{PROJ}/_apis/policy/configurations/2?api-version=6.0" --user "username:password" --request PUT --header "Content-Type: application/json" --data '{\"isEnabled\":false}'
But I end up with the error:
{"$id":"1","innerException":null,"message":"TF400898: An Internal Error Occurred. Activity Id: xxxx-xxxx-xxxx-xxxx-70e5364888b7.","typeName":"Newtonsoft.Json.JsonReaderException, Newtonsoft.Json","typeKey":"JsonReaderException","errorCode":0,"eventId":0}
Is there anything I am missing out in the JSON data to be passed for the PUT method?

There are many branch policies (reviews, builds etc.) and every policy the behavior is different.
For reviewers policy you can use the DELETE API:
https://dev.azure.com/{org}/{project}/_apis/policy/Configurations/{policy-id}?api-version=6.0
In curl the --request should be DELETE.
You can get the policy-id with the GET api you did.

Related

Using wiremock to proxy/record calls to AWS Cloudfront service

We have a container-based service running in AWS ECS with the front end hosted by AWS Cloudfront, and authorization handled by AWS Cognito. I'm trying to configure Wiremock to be a proxy for this service so I can record the calls and mappings to later use in unit tests for a client app I'm writing in python.
I'm running the Wiremock server in standalone mode, and have it proxying to calls to the url of our service. However, Cloudfront keeps returning either a 403-Bad Request error or 403-Forbidden error when I connect via Wiremock.
When I use curl, and pass all the correct headers (Content-Type: application/json, Authentication: Bearer ) it works just fine when I use https://myservice.example.com/api/foo. But as soon as I swap out "myservice.example.com" for "localhost:8000", I get the Cloudfront generated errors.
I'm guessing I have some mis-configuration where, despite passing the headers to Wiremock, I haven't properly told Wiremock to pass those headers on to "the service", which is really Cloudfront.
Not being a Java guy, I'm finding the Wiremock docs a little difficult to understand, and am trying to use the command-line arguments to configure Wiremock like this:
/usr/bin/java -jar \
./wiremock-jre8-standalone-2.35.0.jar \
--port=8000 \
--verbose \
--root-dir=test_data/wiremock \
--enable-browser-proxying \
--preserve-host-header \
--print-all-network-traffic \
--record-mappings \
--trust-proxy-target=https://myservice.example.com \
--proxy-all=https://myservice.example.com
Request:
$ curl -k -X GET -H "Content-Type: application/json" \
-H "Authorization: Bearer ${JWT}" \
http://127.0.0.1:8000/api/foo
Response:
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>CloudFront</center>
</body>
</html>
When using exactly the same curl command, but changing the URL to point directly at my service instead of the proxy, I get the response I expected (hoped for?) through the proxy:
curl -k -X GET -H "Content-Type: application/json" \
-H "Authorization: Bearer ${JWT}" \
https://myservice.example.com/api/foo
[
{
"id": "09d91ea0-7cb0-4786-b3fc-145fc88a1a3b",
"name": "foo",
"created": "2022-06-09T02:32:11Z",
"updated": "2022-06-09T20:08:43Z",
},
{
"id": "fb2b6454-4336-421a-bc2f-f1d588a78d12",
"name": "bar",
"created": "2022-10-05T06:23:24Z",
"updated": "2022-10-05T18:34:32Z",
}
]
Any help would be greatly appreciated.
Thanks.

GitlabAPI PUT approval_rules can't update group_ids

I'm trying to update the group_ids of specific approval rule in a project using the PUT API https://gitlab.com/api/v4/projects/:proj/approval_rules/:ruleId
using this call : curl -s --request PUT --header "PRIVATE-TOKEN: xxx" --data 'name=Approval_ALL_GLs_experts' --data 'approvals_required=1' --data "group_ids[]=:groupId" "https://gitlab.com/api/v4/projects/:proj/approval_rules/xxx"
The problem is that i'm getting the following response: {"id":xxx,"name":"Approval_ALL_GLs_experts","rule_type":"regular","eligible_approvers":[],"approvals_required":1,"users":[],"groups":[],"contains_hidden_groups":false,"protected_branches":[]}
My observation is that it's not working when I'm using a token of an owner of the proj but this user is not part of the groupId.
Using a token of an owner which is part of the groupId will do the work and update it correctly.

How to integrate LiveChat Dashboard with Google Dialogflow for agents handoff?

When user ask or select option for "agent"/"chat with an agent" on google dialogflow chatbot then it should transfer the chat to LiveChat(https://www.livechat.com/) dashboard so that agent take over from chatbot.
To pass data into LiveChat from a page without LiveChat chat window installed on it,
you can use the following method from LiveChat API:
https://developers.livechat.com/docs/messaging/agent-chat-api#create-customer
to create a customer
afterwards, start a chat as that customer:
https://developers.livechat.com/docs/messaging/customer-chat-api#start-chat
once chat is started - you can submit events using this method:
https://developers.livechat.com/docs/messaging/customer-chat-api#send-event
for all of the above you'll need to provide authorization, please see below:
https://developers.livechat.com/docs/authorization/authorizing-api-calls
for authorization you'll need an account in LiveChat Developer Console:
https://developers.livechat.com/console/
In the Console you can also find contact to LiveChat Developer Community (Discord and email)
EDIT: here's how it looks like more hands on:
First thing we need to do is acquire authentication - in this case we want to act as a customer, there are a few ways to authenticate as customer - below are instructions regarding all the methods:
https://developers.livechat.com/docs/authorization/authorizing-api-calls#case-new-customer
I'll use Agent token grant method and acquire Customer access token by sending following curl:
curl --location --request POST 'https://accounts.livechat.com/customer/token' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer dal:xxxFpzmIHk5c86Zwn3uf2YunhGk' \
--data-raw '{
"grant_type": "agent_token",
"client_id": "3xxx45a50544060cedc26c90644f7677",
"response_type": "token",
"redirect_uri": "https://my.livechatinc.com"
}
'
And here's the response received:
{
"access_token": "dal:xxx-zH-fTOKYJsUolAKzow",
"client_id": "xxx145a50544060cedc26c90644f7677",
"entity_id": "xxx1d260-e284-44c0-53d2-3e958f74488a",
"expires_in": 28800,
"token_type": "Bearer"
}
Once customer access token is acquired we'll be looking to send the "start chat" method
This request requires a parameter called "organization_id" - that's an unique identifier of your account across all LiveChat Inc. products that's static so we'll need to only get it once,
you can get it by sending following curl:
curl --location --request GET 'https://api.livechatinc.com/v3.4/configuration/action/get_organization_id?license_id=1234567'
License ID required for the above can be found inside of your LiveChat tracking code here:
https://my.livechatinc.com/settings/code
Sending the request will provide you with "organization_id" in the response:
{
"organization_id": "xxx29b0e-012c-4384-9f72-614324ec0xxx"
}
Now that we have everything - we can start the chat:
curl --location --request POST 'https://api.livechatinc.com/v3.4/customer/action/start_chat?organization_id=xxx29b0e-012c-4384-9f72-614324ec0741' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer dal:xxx-zH-fTOKYJsUolAKzow' \
--data-raw '{}'
And the response looks like this:
{
"chat_id": "R5MUSNS1I5",
"thread_id": "R5MUSNS1J5"
}
chat_id property from the above response will be useful for sending events and resuming the chat should the visitor want to chat again in the future
To send a message we'll be using the "send_event" method, curl below:
curl --location --request POST 'https://api.livechatinc.com/v3.4/customer/action/send_event?organization_id=xxx29b0e-012c-4384-9f72-614324ec0741' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer dal:xxx-zH-fTOKYJsUolAKzow' \
--data-raw '{
"chat_id": "R5MUSNS1I5",
"event": {
"type": "message",
"text": "hello world",
"recipients": "all"
}
}'
And here's the result:
incoming chat
I hope that helps!

Find all of the private packages you have published to GitHub Packages

What's the API call to list all the published packages on GitHub?
I'm looking at GitHub API v4 GraphQL documentation but, since I don't know anything about GraphQL, I can't make sense of it.
At https://help.github.com/en/github/managing-packages-with-github-packages/deleting-a-package#deleting-a-version-of-a-private-package I found
To find all of the private packages you have published to GitHub
Packages, along with the version IDs for the packages, you can use the
registryPackagesForQuery connection. You will need a token with the
read:packages and repo scopes. For more information, see
"registryPackagesForQuery" in the GitHub Developer documentation.
But after that I'm basically lost.
Here a cURL command to use the registryPackagesForQuery function:
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: bearer TOKEN" \
-d '{"query":"{ user(login: \"OWNER\") { registryPackagesForQuery(first: 10, query:\"is:private\") { totalCount nodes { nameWithOwner versions(first: 10) { nodes { id version } } } } }}"}' \
https://api.github.com/graphql
Replace OWNER by your git login, and TOKEN by your personal token.

Connecting Eclipse Hono and Ditto

I have eclipse-hono installed in one machine and Eclipse ditto installed in the other which is connected to same WIFI. I am trying to consume data from Eclipse hono to Eclipse ditto.
I have created a tenant named tenantallAdapters and registered a device named 4716.
Let us assume that I need to send the temperature sensor data from the registered device in the tenant to a Hono consumer as shown in the below snippet.
curl -i -X POST \
-u sensor10#tenantAllAdapters \
-H 'Content-Type: application/json' \
--data-binary '{"temp": 5}' \
http://10.196.2.164:8080/telemetry
I also start the Hono-consumer as below
mvn spring-boot:run -Drun.arguments=\
--hono.client.host=10.196.2.164,\
--hono.client.username=consumer#HONO,\
--hono.client.password=verysecret,\
--hono.auth.amqp.bindAddress=10.196.2.164,\
--hono.auth.amqp.keyPath=target/certs/auth-server-key.pem,\
--hono.auth.amqp.certPath=target/certs/auth-server-cert.pem,\
--hono.auth.amqp.trustStorePath=target/certs/trusted-certs.pem,\
--tenant.id=tenantAllAdapters
I am successfully able to receive the data in Hono consumer.
Instead of Hono consumer, how can I consume the same data in Ditto?
Edited : As per the blog in the first comment below:
“Test connection” command via HTTP in order to test if the Ditto sandbox can connect to the Hono one is as follows
$ curl -X POST -i -u devops:devopsPw1! -H 'Content-Type: application/json' -d '{
"targetActorSelection": "/system/sharding/connection",
"headers": {
"aggregate": false
},
"piggybackCommand": {
"type": "connectivity.commands:testConnection",
"connection": {
"id": "hono-sandbox-connection-1",
"connectionType": "amqp-10",
"connectionStatus": "open",
"uri": "amqp://consumer%40HONO:verysecret#hono.eclipse.org:15672",
"failoverEnabled": true,
"sources": [{
"addresses": [
"telemetry/org.eclipse.ditto",
"event/org.eclipse.ditto"
],
"authorizationContext": ["nginx:demo5"]
}]
}
}
}' https://ditto.eclipse.org/devops/piggyback/connectivity?timeout=8000
I am not sure if I am missing anything
I had followed https://www.eclipse.org/ditto/2018-05-02-connecting-ditto-hono.html even before I posted this question here.
But the only thing I was missing was the password of the devops user. As mentioned earlier and also as mentioned in the given link, I was using devopsPw1! as the password. Hono and Ditto got connected once I changed the password to foobar.

Resources