@@ -589,31 +589,33 @@ func (s *LocalStorage) getAllProjects() ([]*pubsub.ProjectSettings, error) {
589
589
func NewLocalStorage (
590
590
projectIds []ProjectId ,
591
591
xpServer string ,
592
- authzEnabled bool ,
593
592
googleApplicationCredentialsEnvVar string ,
594
593
) (* LocalStorage , error ) {
595
594
// Set up Request Modifiers
596
595
clientOptions := []managementClient.ClientOption {}
597
- if authzEnabled {
598
- var googleClient * http.Client
599
- var err error
600
- // Init Google client for Authz. When using a non-empty googleApplicationCredentialsEnvVar that contains a file
601
- // path to a credentials file, the credentials file MUST contain a Google SERVICE ACCOUNT for authentication to
602
- // work correctly
603
- if filepath := os .Getenv (googleApplicationCredentialsEnvVar ); filepath != "" {
604
- googleClient , err = auth .InitGoogleClientFromCredentialsFile (context .Background (), filepath )
605
- } else {
606
- googleClient , err = auth .InitGoogleClient (context .Background ())
607
- }
608
- if err != nil {
609
- return nil , err
610
- }
611
596
612
- clientOptions = append (
613
- clientOptions ,
614
- managementClient .WithHTTPClient (googleClient ),
615
- )
597
+ httpClient := http .DefaultClient
598
+ var googleClient * http.Client
599
+ var err error
600
+ // Init Google client for Authz. When using a non-empty googleApplicationCredentialsEnvVar that contains a file
601
+ // path to a credentials file, the credentials file MUST contain a Google SERVICE ACCOUNT for authentication to
602
+ // work correctly
603
+ if filepath := os .Getenv (googleApplicationCredentialsEnvVar ); filepath != "" {
604
+ googleClient , err = auth .InitGoogleClientFromCredentialsFile (context .Background (), filepath )
605
+ } else {
606
+ googleClient , err = auth .InitGoogleClient (context .Background ())
616
607
}
608
+
609
+ if err == nil {
610
+ httpClient = googleClient
611
+ } else {
612
+ log .Println ("Google default credential not found. Fallback to HTTP default client" )
613
+ }
614
+
615
+ clientOptions = append (
616
+ clientOptions ,
617
+ managementClient .WithHTTPClient (httpClient ),
618
+ )
617
619
xpClient , err := managementClient .NewClientWithResponses (xpServer , clientOptions ... )
618
620
if err != nil {
619
621
return nil , err
0 commit comments