Dart pub publish gives error after authentication - dart

I wanted to put a small library code to pub.dartlang.org
After calling pub publish, it asked me to Allow accessing my google account for sending files. After I allowed by going to the given browser link, it gave me this error in the command line:
Waiting for your authorization...
Authorization received, processing...
ProcessException: No such file or directory
Command: curl --dump-header /tmp/temp_dir1_CzMqQG/curl-headers --cacert /home/afsina/apps/dart/dart-sdk/util/pub/curl/ca-certificates.crt --request POST --location --max-redirs 5 --data-binary #- --header accept: --header user-agent: --header Content-Type: application/x-www-form-urlencoded; charset=UTF-8 --header content-length: 265 https://accounts.google.com/o/oauth2/token
here is the --verbose output
Looks great! Are you ready to upload your package (y/n)? y
IO : Read line: y
FINE: Loading OAuth2 credentials.
IO : Seeing if file /home/afsina/.pub-cache/credentials.json exists.
IO : File /home/afsina/.pub-cache/credentials.json does not exist.
FINE: No credentials found at /home/afsina/.pub-cache/credentials.json.
MSG : Pub needs your authorization to upload packages on your behalf.
| In a web browser, go to https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force&response_type=code&client_id=818368855108-8grd2eg9tj9f38os6f1urbcvsq399u8n.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A59097&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email
| Then click "Allow access".
|
| Waiting for your authorization...
MSG : Authorization received, processing...
FINE: Sending Curl request POST https://accounts.google.com/o/oauth2/token
IO : Begin create temp directory .
IO : End create temp directory .
IO : Spawning curl --dump-header /tmp/temp_dir1_RpLNu6/curl-headers --cacert /home/afsina/apps/dart/dart-sdk/util/pub/curl/ca-certificates.crt --request POST --location --max-redirs 5 --data-binary #- --header accept: --header user-agent: --header Content-Type: application/x-www-form-urlencoded; charset=UTF-8 --header content-length: 265 https://accounts.google.com/o/oauth2/token
IO : Spawning curl --dump-header /tmp/temp_dir1_RpLNu6/curl-headers --cacert /home/afsina/apps/dart/dart-sdk/util/pub/curl/ca-certificates.crt --request POST --location --max-redirs 5 --data-binary #- --header accept: --header user-agent: --header Content-Type: application/x-www-form-urlencoded; charset=UTF-8 --header content-length: 265 https://accounts.google.com/o/oauth2/token
ERR : ProcessException: No such file or directory
| Command: curl --dump-header /tmp/temp_dir1_RpLNu6/curl-headers --cacert /home/afsina/apps/dart/dart-sdk/util/pub/curl/ca-certificates.crt --request POST --location --max-redirs 5 --data-binary #- --header accept: --header user-agent: --header Content-Type: application/x-www-form-urlencoded; charset=UTF-8 --header content-length: 265 https://accounts.google.com/o/oauth2/token
I am guessing it cannot find the ca-certificates.crt file but not sure why.
Version Info: Dart SDK version 0.2.10.1_r16761
ubuntu linux 12.10 64 bit

My bad, this was because pub has "curl" dependency. After installing curl I could publish the lib.

If you run pub on Linux or Mac, it will assume curl is in your PATH and try to spawn it without an explicit path. On Windows, it will use the included curl binary. Our assumption here was that most *NIX users would have curl installed already.
This curl dependency should be going away soon anyway, but I'm glad you found the solution.

Related

How to make a HEAD request to Docker Hub API to get the manifest?

I need to reach manifests of a lot of images on Docker hub, but every GET request for getting manifest is counted as a pull, as a result, I am restricted by the rate limits of docker hub. Is there a way to get the manifest with a HEAD request instead of GET from the API?
Edit: From Docker registry API documentation :
GET /v2//manifests/: Fetch the manifest identified by name and reference where reference can be a tag or digest. A HEAD request can also be issued to this endpoint to obtain resource information without receiving all data.
So I assume we can get related information with an HEAD request.
A shell script to do that looks like:
#!/bin/sh
ref="${1:-library/ubuntu:latest}"
sha="${ref#*#}"
if [ "$sha" = "$ref" ]; then
sha=""
fi
wosha="${ref%%#*}"
repo="${wosha%:*}"
tag="${wosha##*:}"
if [ "$tag" = "$wosha" ]; then
tag="latest"
fi
apio="application/vnd.oci.image.index.v1+json"
apiol="application/vnd.oci.image.manifest.v1+json"
apid="application/vnd.docker.distribution.manifest.v2+json"
apidl="application/vnd.docker.distribution.manifest.list.v2+json"
token=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repo}:pull" \
| jq -r '.token')
curl -H "Accept: ${apio}" -H "Accept: ${apiol}" -H "Accept: ${apid}" -H "Accept: ${apidl}" \
-H "Authorization: Bearer $token" \
-I -s "https://registry-1.docker.io/v2/${repo}/manifests/${sha:-$tag}"
Note that the head request only shows the headers, and the most useful one is docker-content-digest so you can get the digest for a specific tag:
HTTP/1.1 200 OK
content-length: 1416
content-type: application/vnd.docker.distribution.manifest.list.v2+json
docker-content-digest: sha256:20fa2d7bb4de7723f542be5923b06c4d704370f0390e4ae9e1c833c8785644c1
docker-distribution-api-version: registry/2.0
etag: "sha256:20fa2d7bb4de7723f542be5923b06c4d704370f0390e4ae9e1c833c8785644c1"
date: Thu, 08 Sep 2022 17:45:42 GMT
strict-transport-security: max-age=31536000
ratelimit-limit: 100;w=21600
ratelimit-remaining: 100;w=21600
docker-ratelimit-source: 68.100.24.47
If you want to do this for other registries, you'll need to adjust the authentication. Both go-containerregistry's crane and regclient's regctl tools have image digest commands that handle the authentication and return just the digest.

Unable to add a group member using microsoft graph api in a bash script

If I run below http script from the graph.microsoft.com docs, it works fine.
POST https://graph.microsoft.com/v1.0/groups/9746dce-f530182/members/$ref
Content-type: application/json
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI6Il9Y-pCiTwLhttVX5wg
{
"#odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/e7cb-2f96bba6"
}
where:
9746dce-f530182 = group-id,
e7cb-2f96bba6 = user-id and
eyJ0eXAiOiJKV1QiLCJub25jZSI6Il9Y-pCiTwLhttVX5wg = auth-token
I would like to run this as a bash script, so that I can automate the token generation and the POST call. My script looks like so.
CLIENT_ID='283f4d25-87bde0ef'
TENANT_ID='2d987312-a4ff5ea0'
CLIENT_SECRET='XSY8Q~4Ls-ahi'
GROUP_ID="9746dc-00182"
USER_ID='e7cb46-bbbba6'
AT_URL="https://login.microsoftonline.com/${TENANT_ID}/oauth2/token"
auth_response=$(curl -X POST -d 'grant_type=client_credentials&client_id='${CLIENT_ID}'&client_secret='$CLIENT_SECRET'&resource=https://graph.microsoft.com' $AT_URL | jq .)
token="$(echo $auth_response | jq -r .token_type) $(echo $auth_response | jq -r .access_token)"
curl -H "Authorization: $token" -H "Content-type: application/json" -d '{"#odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/'$USER_ID'"}' "https://graph.microsoft.com/v1.0/groups/$GROUP_ID/members/$ref"
But this fails with the below error. What am I missing?
{"error":{"code":"Request_BadRequest","message":"Unsupported resource type 'DirectoryObject' for operation 'Create'.","innerError":{"date":"2022-05-25T11:24:21","request-id":"e189dc-063e","client-request-id":"e189d-2e42063e"}}}
I managed to fis the issue by changing the last line of the script to the following. The problem was that the $ref at the end of the URL was treated as a bash variable.
curl -H "Authorization: $token" -H "Content-Type: application/json" -d '{"#odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/'${USER_ID}'"}' 'https://graph.microsoft.com/v1.0/groups/'$GROUP_ID'/members/$ref'
Hope this helps someone else.
The final script looks like below
CLIENT_ID='283f4d25-87bde0ef'
TENANT_ID='2d987312-a4ff5ea0'
CLIENT_SECRET='XSY8Q~4Ls-ahi'
GROUP_ID="9746dc-00182"
USER_ID='e7cb46-bbbba6'
AT_URL="https://login.microsoftonline.com/${TENANT_ID}/oauth2/token"
auth_response=$(curl -X POST -d 'grant_type=client_credentials&client_id='${CLIENT_ID}'&client_secret='$CLIENT_SECRET'&resource=https://graph.microsoft.com' $AT_URL | jq .)
token="$(echo $auth_response | jq -r .token_type) $(echo $auth_response | jq -r .access_token)"
curl -H "Authorization: $token" -H "Content-Type: application/json" -d '{"#odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/'${USER_ID}'"}' 'https://graph.microsoft.com/v1.0/groups/'$GROUP_ID'/members/$ref'

Cookies don't work in dart but curl generated by CurlLoggerDioInterceptor works in shell

I have in my Flutter project APIs that use cookies and they don't work. I have enabled the interceptor that generates the curl:
CurlLoggerDioInterceptor (printOnSuccess: true)
with the following result:
curl -i \
-H "Accept: application / json" \
-H "Connection: keep-alive" \
-H "cookie: ci_session = uv0hts7fb8us0r7m5vvaa64p4o89u9he" \
-H "Authorization: 1652292531" \
"http://xxxxx.it"
And this works on shell. I don't understand, why the curl generated by Dart code works and the code itself doesn't work?
Regarding the code I've used all the solutions in this link (dio_cookie_manager, NetworkService, HTTP request instead of dio...) How do I make an http request using cookies on flutter?
With Dio is not possible, but with the following library yes:
flutter_curl: ^0.1.1

How to get build status of PR using BitBucket API?

Not getting Build job details/status of the PR when using Bitbucket API for any pull request
Here is my API URL:
https://example.com/rest/api/1.0/projects/{projectkey}/repos/{reposlug}/pull-requests/{pullrequestID}
How Build status looks like on GUI:
I also tried below methods to get the Build status but no luck
/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/pull-requests
/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks
So I wanted to get whether build status of any PR whether it is Success or Fail
Thanks in Advance for your answers.
The build status is on the commit, not on the PR. First you should find the latest commit of the source branch by calling /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}. see the docs for more details
Once you have the commit id you can query the build-status api by calling /rest/build-status/1.0/commits/{commitId}. See the docs for more details
Using API 2.0
Get statuses: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/statuses
Set status: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bnode%7D/statuses/build
Example:
curl --request GET \
--url https://api.bitbucket.org/2.0/repositories/piavita/com.piavita-vet.ios/pullrequests/300/statuses \
--header 'Authorization: Basic SecretKey' \
--header 'Content-Type: application/json'
curl --request POST \
--url https://api.bitbucket.org/2.0/repositories/piavita/com.piavita-vet.ios/commit/8619291af393/statuses/build \
--header 'Authorization: Basic SecretKey' \
--header 'Connection: keep-alive' \
--data '{\n "url": "http://jenkins.ddns.net:8080/job/jobName/123/",\n "state": "SUCCESSFUL",\n "key": "JENKINS"\n}'

Error delete image from Docker Registry using API v2

I'm trying to remove images from Docker Registry using API v2 folloving сommand:
curl -k -v -u 'docker:sdf' -X DELETE https://localhost:5000/v2/bkf/ebbg/manifests/1
But I get next error:
> DELETE /v2/bkf/ebbg/manifests/1 HTTP/1.1
> Authorization: Basic ZG9ja2VyOkRrZmxidmJoMjAx==
> User-Agent: curl/7.35.0
> Host: localhost:5000
> Accept: */*
>
< HTTP/1.1 400 Bad Request
< Content-Type: application/json; charset=utf-8
< Docker-Distribution-Api-Version: registry/2.0
< X-Content-Type-Options: nosniff
< Date: Mon, 14 Mar 2016 07:56:13 GMT
< Content-Length: 98
<
{"errors":[{"code":"DIGEST_INVALID","message":"provided digest did not match uploaded content"}]}
Command:
curl -u 'docker:sdf' -X GET https://localhost:5000/v2/_catalog
show
{"repositories":["bkf/ebbg"]}
comand
curl -k -u 'docker:sdf' -X GET https://localhost:5000/v2/bkf/ebbg/tags/list
show
{"name":"bkf/ebbg","tags":["32","1","latest","12","33","34"]}
In what may be a problem or where did I go wrong?
I managed to get this working with deleting a tag but the repository still remains.
The first command you need will get you the digest:
curl -k -v -u 'docker:sdf' -X HEAD -v https://localhost:5000/v2/bkf/ebbg/manifests/1
That will return the in the header the digest you need.
< Docker-Content-Digest: sha256:xxxxxxx
You will then need to make the DELETE call using the digest:
curl -k -v -u 'docker:sdf' -X DELETE -v --header "Accept: application/vnd.docker.distribution.manifest.v2+json" https://localhost:5000/v2/bkf/ebbg/manifests/sha256:xxxxxxx
If successful it will return:
202 Accepted
This does remove the tag but, like I said, the repository still remains. I will need to do some more work on this to figure out why.
The answer to your use case probably is delete_docker_registry_image.py
I tried it on my registry and obviously it did the trick :)
As reading the python source code isn't too complicated, you can get from there what is done when and how - or simply just use it :P
hope it helps ...

Resources