2020import com .google .auth .appengine .AppEngineCredentials ;
2121import com .google .auth .oauth2 .ComputeEngineCredentials ;
2222import com .google .auth .oauth2 .GoogleCredentials ;
23+ import com .google .cloud .language .v2 .AnalyzeSentimentResponse ;
24+ import com .google .cloud .language .v2 .Document ;
25+ import com .google .cloud .language .v2 .LanguageServiceClient ;
26+ import com .google .cloud .language .v2 .LanguageServiceSettings ;
2327import com .google .cloud .storage .Bucket ;
2428import com .google .cloud .storage .Storage ;
2529import com .google .cloud .storage .StorageOptions ;
2630import com .google .common .collect .Lists ;
2731import java .io .FileInputStream ;
2832import java .io .IOException ;
29- import com .google .cloud .language .v2 .AnalyzeSentimentResponse ;
30- import com .google .cloud .language .v2 .Document ;
31- import com .google .cloud .language .v2 .LanguageServiceClient ;
32- import com .google .cloud .language .v2 .LanguageServiceSettings ;
3333
34- /**
35- * Demonstrate various ways to authenticate requests using Cloud Storage as an example call.
36- */
34+ /** Demonstrate various ways to authenticate requests using Cloud Storage as an example call. */
3735public class AuthExample {
3836 // [START auth_cloud_implicit]
3937 static void authImplicit () {
@@ -53,8 +51,9 @@ static void authImplicit() {
5351 static void authExplicit (String jsonPath ) throws IOException {
5452 // You can specify a credential file by providing a path to GoogleCredentials.
5553 // Otherwise credentials are read from the GOOGLE_APPLICATION_CREDENTIALS environment variable.
56- GoogleCredentials credentials = GoogleCredentials .fromStream (new FileInputStream (jsonPath ))
57- .createScoped (Lists .newArrayList ("https://www.googleapis.com/auth/cloud-platform" ));
54+ GoogleCredentials credentials =
55+ GoogleCredentials .fromStream (new FileInputStream (jsonPath ))
56+ .createScoped (Lists .newArrayList ("https://www.googleapis.com/auth/cloud-platform" ));
5857 Storage storage = StorageOptions .newBuilder ().setCredentials (credentials ).build ().getService ();
5958
6059 System .out .println ("Buckets:" );
@@ -130,13 +129,13 @@ public static void main(String[] args) throws IOException {
130129 return ;
131130 }
132131 if ("apikey" .equals (args [0 ])) {
133- if (args .length >= 2 ) {
134- authApiKey (args [1 ]);
135- } else {
136- throw new IllegalArgumentException ("Api key is required with 'apikey'." );
137- }
138- return ;
132+ if (args .length >= 2 ) {
133+ authApiKey (args [1 ]);
134+ } else {
135+ throw new IllegalArgumentException ("Api key is required with 'apikey'." );
139136 }
137+ return ;
138+ }
140139
141140 authImplicit ();
142141 }
0 commit comments