I'm trying to use GCP API to download a file from Artifact Registry, and I don't understand how to do it.
The doc (link) states that
Response body - If successful, the response body is empty.
But it also states that this method:
Download a file.
So where should I find the said file?
I tried it with Postman and curl, and as described - the content is empty and I don't get the file:
$ curl --location 'https://artifactregistry.us-central1.rep.googleapis.com/v1/projects/<PROJ_ID>/locations/us-central1/repositories/<REPO_NAME>/files/<ARTIFACT_NAME>:<VERSION>:<FILE_PATH>:download' --header 'Authorization: Bearer ...'
{}
If I omit the ":download" part to use the 'get' command (link) I'm getting a valid and correct response with all the metadata:
$ curl --location 'https://artifactregistry.us-central1.rep.googleapis.com/v1/projects/<PROJ_ID>/locations/us-central1/repositories/<REPO_NAME>/files/<ARTIFACT_NAME>:<VERSION>:<FILE_PATH>' --header 'Authorization: Bearer ...'
{
"name": "projects/.../locations/us-central1/repositories/.../files/...:...:...",
"sizeBytes": "1373",
"hashes": [ ... ],
"createTime": "...",
"updateTime": "...",
"owner": "projects/.../locations/us-central1/repositories/.../packages/.../versions/..."
}
Any direction?
gcloud
's --log-http
flag is priceless in understanding the underlying (REST) calls made by gcloud
.
PROJECT="..."
LOCATION="..."
REPO="..."
Pick one of the following and assign to FILE
:
gcloud artifacts files list \
--location=${LOCATION} \
--repository=${REPO} \
--project=${PROJECT} \
--format="value(name)"
Then observe gcloud --log-http
:
gcloud artifacts files download ${FILE} \
--location=${LOCATION} \
--repository=${REPO} \
--project=${PROJECT} \
--destination=.
And recreate using curl
:
TOKEN=$(gcloud auth print-access-token)
NAME="projects/${PROJECT}/locations/${LOCATION}/repositories/${REPO}/files/${FILE}"
curl \
--get \
--header "Authorization: Bearer ${TOKEN}" \
--data-urlencode "alt=media" \
"https://artifactregistry.googleapis.com/v1/${NAME}:download" \
--output foo
ls -la foo