How list available BigQuery projects without parent?

132 views Asked by At

I am using Java client and I would like to list all projects that user has access to (as it appears in GCP console).

  1. As documentation says it is recommended to use ResourceManager library instead of BigQuery (BigQuery library has no classes to retrieve projects - there is another one called Bigquery (small q) that has some api for calling project, but documentation claims it is using ResourceManager underneath.
  2. I tried using v3 library version of ResourceManager but apparently it always requires the parent id, but I don't want to give access for listing the folder above because in much more complicated architecture I would have to give access to all organisations and folders and prepare search of all projects. I would like only list projects that current user has access to.
  3. There is also possibility to use same library but with v1 api version which works like a charm... but it is deprecated and I am not sure how long it will be supported.
  4. I don't want to use any other clients than Java.

Do you know solution using ResourceManager but not with parent or without granting too many privileges?

1

There are 1 answers

0
kasiacode On

Apparently the replacement for list is search method with empty query string:

ProjectsSettings projectsSettings = ProjectsSettings.newBuilder().build();
ProjectsClient projectsClient = ProjectsClient.create(projectsSettings);

ProjectsClient.SearchProjectsPagedResponse searchProjectsPagedResponse = projectsClient.searchProjects("");

for (Project project : searchProjectsPagedResponse.iterateAll()) {
        System.out.println(project.getDisplayName());
};