How do I get revision tags from google cloud source repository via curl?

Viewed 295

What I want

  1. I have a python backend application, using a service account, running in docker.
  2. I have a cloud build trigger that is connected to a bitbucket repository. This trigger uses a webhook. For revision I use tags.
  3. I want to trigger this webhook with my backend application. I want to provide a specific tag (using a placeholder variable).
  4. I want the backend to give me a list of all available tags (like I get on the console.google.com frontend, see screenshot)

Revision tags in build trigger

What I tried

I tried this API endpoint using a Bearer token (which works fine), but it doesn't provide me with a tag list: Source Repo API

curl https://sourcerepo.googleapis.com/v1/projects/<project>/repos/<repo>' --header "Authorization: Bearer $(gcloud auth print-access-token)" --header 'Accept: application/json'

Because it is possible to retrieve all tags in the cloud console, I used the developer tools to find the endpoint that provides me with all available tags:

console.google.com endpoint

https://console.cloud.google.com/m/source/repos/get?project=<project>&repo=<repo>

My issue here is that it takes cookies to authenticate, if I use the Bearer token it does not work.

Is it possible to authenticate my service account automatically against console.google.com to use this endpoint? Or is there another way to get a list of tags?

1 Answers

From what you have explained I understand that your concerns are:

1. If there is a way to get the list of tags from your repository that you are able to see in the GCP console using the endpoint that you have found.

The information that the console displays regarding tags do not come from any REST or gRPC API (the APIs provided by Google), but rather it comes directly from the git API. The console frontend runs a command similar to git tag in order to get the tags from your repository. The tags are not stored within the GCP system, the console only queries the git repo for the tags.

2. Can I authenticate with a service account on the console?

No. The APIs used by the web frontends (i.e. APIs starting with https://console.cloud.google.com) will only allow cookie authentication, which only user accounts can obtain. There is usually a way to translate a frontend API (https://console.cloud.google.com) to a GCP API (https://*.googleapis.com), where you can use regular authentication to retrieve the information. However,in this case, the tag information is not in a GCP API (but rather inside the git repo), so there is no translation available.

3. If there is another way to list the possible tags present in the repository?

I tried to reproduce your situation to find a way to be able to get the list of the tags present in one repository, in this case a Bitbucket repository, and I found that you will be able to get this data using the $ git tag command. In this documentation you will be able to find all the commands related to Repository tags. Knowing this, after linking the Bitbucket Repository to my code, I was able to get the list of tags after using the $ git tag command.

Related