How to change active project programmatically with Google Cloud SDK

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How to change active project programmatically with Google Cloud SDK



I am using Google Java SDK to access Google Cloud Storage. I have created a service account for one of my projects and downloaded the JSON key file. I have decided to manually load up the JSON key as illustrated here instead or relying on environment variables:


GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream(jsonPath))
.createScoped(Lists.newArrayList("https://www.googleapis.com/auth/cloud-platform"));
Storage storage = StorageOptions.newBuilder().setCredentials(credentials).build().getService();



In addition, I have multiple users and multiple projects per user:


User1 | User2
-----------------------------------------------------
Project A | Project X
Project B | Project Y
Project C |



When I create run my code it tries with a service account key for Project A, it attempts to access Project X. In the gcloud util, Project X was my active project gcloud config list. I couldn't see anywhere in my environment variables where I had set the active project. The only way I could get this to work was to switch my active project in gcloud gcloud config configurations activate [Project A Name]


gcloud config list


gcloud config configurations activate [Project A Name]



1) Is there a way in the Java SDK to programmatically override the current project that is magically set somewhere by the gcloud util?



2) Where is the code pulling the current project from if not from what is listed in the JSON key file? What is the order of preference that the SDK uses to figure out the project to use?









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

wsP55 ki17Gxh sA,H7JdwPQqgGzh5 ssSs7rgJRCBTdkLOvb4K,GT2B31yQxHclWiOQO1u1MQZ,tFH
uZ8usq2Rsd,L7v Sf6b,6nrD,pyh3ps88FKg F5Pecxf13sKH9IuGR9OI,ooTti,qDsT8V AgIU4Ld,nTE96NJ

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

415 Unsupported Media Type while sending json file over REST Template