Skip to content

ProjectId override question #979

Closed
Closed
@fondberg

Description

@fondberg

After following the procedures outlined in the README (here) for creating a service account for machine integration the projectId is correctly set in the json key file however the usage of it is not.

I have two questions that I hope I can get help with:

  • When changing the project_id in code some project which is wrong it still works. Can someone explain if the gcloud-java or the Google Cloud service stores or parses the service account to extract the correct project_id?
Storage storage = StorageOptions.builder() 
  .authCredentials(AuthCredentials.createForJson(new FileInputStream("/path/to/my/key.json"))
  .projectId("projectDoesNotExist") // <---- HERE
  .build()
  .service();
// It is possible to use the Storage.writer and upload correctly to the service accounts project_id!!!
  • Reading Specifying a Project ID there are various ways to set the project id, however none using the following flow from code. Question is if it would be good if the StorageOptions.builder() could take a file String as argument?
//Todays API
Storage storage = StorageOptions.builder() 
  .authCredentials(AuthCredentials.createForJson(new FileInputStream("/path/to/my/key.json"))
  .build()
  .service();
//here the project_id of StorageOptions is never set if no environment variable is set as the json project_id is never parsed
//Proposed API change which automatically uses AuthCredentials is the json file is supplied
Storage storage = StorageOptions.builder("/path/to/my/key.json") 
  .build()
  .service();

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions