File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
core/src/main/java/com/google/cloud/sql/core Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 1717package com .google .cloud .sql .core ;
1818
1919import com .google .api .client .http .HttpRequestInitializer ;
20+ import com .google .api .services .sqladmin .SQLAdminScopes ;
2021import com .google .auth .http .HttpCredentialsAdapter ;
2122import com .google .auth .oauth2 .GoogleCredentials ;
2223import com .google .cloud .sql .CredentialFactory ;
2324import java .io .FileInputStream ;
2425import java .io .IOException ;
26+ import java .util .Arrays ;
2527
2628class FileCredentialFactory implements CredentialFactory {
2729 private final String path ;
@@ -37,10 +39,19 @@ public HttpRequestInitializer create() {
3739
3840 @ Override
3941 public GoogleCredentials getCredentials () {
42+ GoogleCredentials credentials ;
4043 try {
41- return GoogleCredentials .fromStream (new FileInputStream (path ));
44+ credentials = GoogleCredentials .fromStream (new FileInputStream (path ));
4245 } catch (IOException e ) {
4346 throw new IllegalStateException ("Unable to load GoogleCredentials from file " + path , e );
4447 }
48+
49+ if (credentials .createScopedRequired ()) {
50+ credentials =
51+ credentials .createScoped (
52+ Arrays .asList (SQLAdminScopes .SQLSERVICE_ADMIN , SQLAdminScopes .CLOUD_PLATFORM ));
53+ }
54+
55+ return credentials ;
4556 }
4657}
You can’t perform that action at this time.
0 commit comments