@@ -45,8 +45,8 @@ public class RemoteGcsHelper {
45
45
46
46
private static final Logger log = Logger .getLogger (RemoteGcsHelper .class .getName ());
47
47
private static final String BUCKET_NAME_PREFIX = "gcloud-test-bucket-temp-" ;
48
- private static final String PROJECT_ID_ENV_VAR = "GCLOUD_TESTS_PROJECT_ID " ;
49
- private static final String PRIVATE_KEY_ENV_VAR = "GCLOUD_TESTS_KEY " ;
48
+ private static final String PROJECT_ID_ENV_VAR = "GCLOUD_PROJECT " ;
49
+ private static final String PRIVATE_KEY_ENV_VAR = "GOOGLE_APPLICATION_CREDENTIALS " ;
50
50
private final StorageOptions options ;
51
51
52
52
private RemoteGcsHelper (StorageOptions options ) {
@@ -107,13 +107,7 @@ public static RemoteGcsHelper create(String projectId, InputStream keyStream)
107
107
StorageOptions storageOptions = StorageOptions .builder ()
108
108
.authCredentials (AuthCredentials .createForJson (keyStream ))
109
109
.projectId (projectId )
110
- .retryParams (RetryParams .builder ()
111
- .retryMaxAttempts (10 )
112
- .retryMinAttempts (6 )
113
- .maxRetryDelayMillis (30000 )
114
- .totalRetryPeriodMillis (120000 )
115
- .initialRetryDelayMillis (250 )
116
- .build ())
110
+ .retryParams (retryParams ())
117
111
.connectTimeout (60000 )
118
112
.readTimeout (60000 )
119
113
.build ();
@@ -145,41 +139,30 @@ public static RemoteGcsHelper create(String projectId, String keyPath)
145
139
log .log (Level .WARNING , ex .getMessage ());
146
140
}
147
141
throw GcsHelperException .translate (ex );
148
- } catch (IOException ex ) {
149
- if (log .isLoggable (Level .WARNING )) {
150
- log .log (Level .WARNING , ex .getMessage ());
151
- }
152
- throw GcsHelperException .translate (ex );
153
142
}
154
143
}
155
144
156
145
/**
157
- * Creates a {@code RemoteGcsHelper} object. Project id and path to JSON key are read from two
158
- * environment variables: {@code GCLOUD_TESTS_PROJECT_ID} and {@code GCLOUD_TESTS_KEY}.
159
- *
160
- * @return A {@code RemoteGcsHelper} object for the provided options.
161
- * @throws com.google.gcloud.storage.testing.RemoteGcsHelper.GcsHelperException if environment
162
- * variables {@code GCLOUD_TESTS_PROJECT_ID} and {@code GCLOUD_TESTS_KEY} are not set or if
163
- * the file pointed by {@code GCLOUD_TESTS_KEY} does not exist
146
+ * Creates a {@code RemoteGcsHelper} object using default project id and authentication
147
+ * credentials.
164
148
*/
165
149
public static RemoteGcsHelper create () throws GcsHelperException {
166
- String projectId = System .getenv (PROJECT_ID_ENV_VAR );
167
- String keyPath = System .getenv (PRIVATE_KEY_ENV_VAR );
168
- if (projectId == null ) {
169
- String message = "Environment variable " + PROJECT_ID_ENV_VAR + " not set" ;
170
- if (log .isLoggable (Level .WARNING )) {
171
- log .log (Level .WARNING , message );
172
- }
173
- throw new GcsHelperException (message );
174
- }
175
- if (keyPath == null ) {
176
- String message = "Environment variable " + PRIVATE_KEY_ENV_VAR + " not set" ;
177
- if (log .isLoggable (Level .WARNING )) {
178
- log .log (Level .WARNING , message );
179
- }
180
- throw new GcsHelperException (message );
181
- }
182
- return create (projectId , keyPath );
150
+ StorageOptions storageOptions = StorageOptions .builder ()
151
+ .retryParams (retryParams ())
152
+ .connectTimeout (60000 )
153
+ .readTimeout (60000 )
154
+ .build ();
155
+ return new RemoteGcsHelper (storageOptions );
156
+ }
157
+
158
+ private static RetryParams retryParams () {
159
+ return RetryParams .builder ()
160
+ .retryMaxAttempts (10 )
161
+ .retryMinAttempts (6 )
162
+ .maxRetryDelayMillis (30000 )
163
+ .totalRetryPeriodMillis (120000 )
164
+ .initialRetryDelayMillis (250 )
165
+ .build ();
183
166
}
184
167
185
168
private static class DeleteBucketTask implements Callable <Boolean > {
0 commit comments