Skip to content

Commit cfec8a2

Browse files
committed
---
yaml --- r: 1955 b: refs/heads/pubsub-alpha c: 76cb620 h: refs/heads/master i: 1953: d902c74 1951: d3ecfdb
1 parent a654ed4 commit cfec8a2

10 files changed

Lines changed: 58 additions & 56 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ refs/heads/master: 689bbb466df4b2d5d2483d6edb8ac5c7c7f7c6fa
33
refs/heads/travis: e21ee7b88a5edc3f3d8c71f90c3fc32abf7e8dd6
44
refs/heads/gh-pages: 4e0561bb4504bf647db669a14417b2b2c87ba45d
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3
6-
refs/heads/pubsub-alpha: 101048e5c2cdca9af55e284554b1f8e0e98dc969
6+
refs/heads/pubsub-alpha: 76cb620fc814083926e03bd981f7aefbf316f4ff
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
88
refs/heads/update-datastore: 482954f2c5055231e5b3122ea91d2ba00ce8187c
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

branches/pubsub-alpha/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ import com.google.gcloud.storage.StorageOptions;
164164
import java.nio.ByteBuffer;
165165
import java.nio.channels.WritableByteChannel;
166166
167-
Storage storage = StorageOptions.defaultInstance().service();
167+
StorageOptions options = StorageOptions.builder().projectId("project").build();
168+
Storage storage = options.service();
168169
BlobId blobId = BlobId.of("bucket", "blob_name");
169170
Blob blob = Blob.load(storage, blobId);
170171
if (blob == null) {

branches/pubsub-alpha/gcloud-java-core/src/main/java/com/google/gcloud/AuthCredentials.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import com.google.api.client.json.jackson.JacksonFactory;
2929
import com.google.auth.http.HttpCredentialsAdapter;
3030
import com.google.auth.oauth2.GoogleCredentials;
31-
import com.google.auth.oauth2.ServiceAccountCredentials;
3231

3332
import java.io.IOException;
3433
import java.io.InputStream;
@@ -213,7 +212,7 @@ public RestorableState<AuthCredentials> capture() {
213212
}
214213
}
215214

216-
public static class ApplicationDefaultAuthCredentials extends AuthCredentials {
215+
private static class ApplicationDefaultAuthCredentials extends AuthCredentials {
217216

218217
private GoogleCredentials googleCredentials;
219218

@@ -256,15 +255,6 @@ protected HttpRequestInitializer httpRequestInitializer(HttpTransport transport,
256255
return new HttpCredentialsAdapter(googleCredentials.createScoped(scopes));
257256
}
258257

259-
public ServiceAccountAuthCredentials toServiceAccountCredentials() {
260-
if (googleCredentials instanceof ServiceAccountCredentials) {
261-
ServiceAccountCredentials credentials = (ServiceAccountCredentials) googleCredentials;
262-
return new ServiceAccountAuthCredentials(credentials.getClientEmail(),
263-
credentials.getPrivateKey());
264-
}
265-
return null;
266-
}
267-
268258
@Override
269259
public RestorableState<AuthCredentials> capture() {
270260
return STATE;

branches/pubsub-alpha/gcloud-java-storage/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ import com.google.gcloud.storage.StorageOptions;
6868
import java.nio.ByteBuffer;
6969
import java.nio.channels.WritableByteChannel;
7070

71-
Storage storage = StorageOptions.defaultInstance().service();
71+
Storage storage = StorageOptions.getDefaultInstance().service();
7272
Blob blob = new Blob(storage, "bucket", "blob_name");
7373
if (!blob.exists()) {
7474
storage2.create(blob.info(), "Hello, Cloud Storage!".getBytes(UTF_8));

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public CopyWriter copyTo(BlobId targetBlob, BlobSourceOption... options) {
281281
* Deletes this blob.
282282
*
283283
* @param options blob delete options
284-
* @return true if blob was deleted
284+
* @return {@code true} if blob was deleted, {@code false} if it was not found
285285
* @throws StorageException upon failure
286286
*/
287287
public boolean delete(BlobSourceOption... options) {
@@ -422,8 +422,8 @@ public Blob apply(BlobInfo f) {
422422
* @param storage the storage service used to issue the request
423423
* @param blobs the blobs to delete
424424
* @return an immutable list of booleans. If a blob has been deleted the corresponding item in the
425-
* list is {@code true}. If deletion failed or access to the resource was denied the item is
426-
* {@code false}.
425+
* list is {@code true}. If a blob was not found, deletion failed or access to the resource
426+
* was denied the corresponding item is {@code false}.
427427
* @throws StorageException upon failure
428428
*/
429429
public static List<Boolean> delete(Storage storage, BlobId... blobs) {

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Bucket.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public Bucket update(BucketInfo bucketInfo, BucketTargetOption... options) {
271271
* Deletes this bucket.
272272
*
273273
* @param options bucket delete options
274-
* @return true if bucket was deleted
274+
* @return {@code true} if bucket was deleted, {@code false} if it was not found
275275
* @throws StorageException upon failure
276276
*/
277277
public boolean delete(BucketSourceOption... options) {

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,31 +1316,31 @@ private static void checkContentType(BlobInfo blobInfo) throws IllegalArgumentEx
13161316
/**
13171317
* Delete the requested bucket.
13181318
*
1319-
* @return true if bucket was deleted
1319+
* @return {@code true} if bucket was deleted, {@code false} if it was not found
13201320
* @throws StorageException upon failure
13211321
*/
13221322
boolean delete(String bucket, BucketSourceOption... options);
13231323

13241324
/**
13251325
* Delete the requested blob.
13261326
*
1327-
* @return true if blob was deleted
1327+
* @return {@code true} if blob was deleted, {@code false} if it was not found
13281328
* @throws StorageException upon failure
13291329
*/
13301330
boolean delete(String bucket, String blob, BlobSourceOption... options);
13311331

13321332
/**
13331333
* Delete the requested blob.
13341334
*
1335-
* @return true if blob was deleted
1335+
* @return {@code true} if blob was deleted, {@code false} if it was not found
13361336
* @throws StorageException upon failure
13371337
*/
13381338
boolean delete(BlobId blob, BlobSourceOption... options);
13391339

13401340
/**
13411341
* Delete the requested blob.
13421342
*
1343-
* @return true if blob was deleted
1343+
* @return {@code true} if blob was deleted, {@code false} if it was not found
13441344
* @throws StorageException upon failure
13451345
*/
13461346
boolean delete(BlobId blob);
@@ -1478,8 +1478,8 @@ private static void checkContentType(BlobInfo blobInfo) throws IllegalArgumentEx
14781478
*
14791479
* @param blobIds blobs to delete
14801480
* @return an immutable list of booleans. If a blob has been deleted the corresponding item in the
1481-
* list is {@code true}. If deletion failed or access to the resource was denied the item is
1482-
* {@code false}.
1481+
* list is {@code true}. If a blob was not found, deletion failed or access to the resource
1482+
* was denied the corresponding item is {@code false}.
14831483
* @throws StorageException upon failure
14841484
*/
14851485
List<Boolean> delete(BlobId... blobIds);

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
import com.google.common.hash.Hashing;
4444
import com.google.common.io.BaseEncoding;
4545
import com.google.common.primitives.Ints;
46-
import com.google.gcloud.AuthCredentials;
47-
import com.google.gcloud.AuthCredentials.ApplicationDefaultAuthCredentials;
4846
import com.google.gcloud.AuthCredentials.ServiceAccountAuthCredentials;
4947
import com.google.gcloud.PageImpl;
5048
import com.google.gcloud.BaseService;
@@ -586,15 +584,9 @@ public URL signUrl(BlobInfo blobInfo, long duration, TimeUnit unit, SignUrlOptio
586584
ServiceAccountAuthCredentials cred =
587585
(ServiceAccountAuthCredentials) optionMap.get(SignUrlOption.Option.SERVICE_ACCOUNT_CRED);
588586
if (cred == null) {
589-
AuthCredentials serviceCred = this.options().authCredentials();
590-
if (serviceCred instanceof ServiceAccountAuthCredentials) {
591-
cred = (ServiceAccountAuthCredentials) serviceCred;
592-
} else {
593-
if (serviceCred instanceof ApplicationDefaultAuthCredentials) {
594-
cred = ((ApplicationDefaultAuthCredentials) serviceCred).toServiceAccountCredentials();
595-
}
596-
}
597-
checkArgument(cred != null, "Signing key was not provided and could not be derived");
587+
checkArgument(options().authCredentials() instanceof ServiceAccountAuthCredentials,
588+
"Signing key was not provided and could not be derived");
589+
cred = (ServiceAccountAuthCredentials) this.options().authCredentials();
598590
}
599591
// construct signature - see https://cloud.google.com/storage/docs/access-control#Signed-URLs
600592
StringBuilder stBuilder = new StringBuilder();

branches/pubsub-alpha/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public class RemoteGcsHelper {
4545

4646
private static final Logger log = Logger.getLogger(RemoteGcsHelper.class.getName());
4747
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";
4850
private final StorageOptions options;
4951

5052
private RemoteGcsHelper(StorageOptions options) {
@@ -105,7 +107,13 @@ public static RemoteGcsHelper create(String projectId, InputStream keyStream)
105107
StorageOptions storageOptions = StorageOptions.builder()
106108
.authCredentials(AuthCredentials.createForJson(keyStream))
107109
.projectId(projectId)
108-
.retryParams(retryParams())
110+
.retryParams(RetryParams.builder()
111+
.retryMaxAttempts(10)
112+
.retryMinAttempts(6)
113+
.maxRetryDelayMillis(30000)
114+
.totalRetryPeriodMillis(120000)
115+
.initialRetryDelayMillis(250)
116+
.build())
109117
.connectTimeout(60000)
110118
.readTimeout(60000)
111119
.build();
@@ -137,30 +145,41 @@ public static RemoteGcsHelper create(String projectId, String keyPath)
137145
log.log(Level.WARNING, ex.getMessage());
138146
}
139147
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);
140153
}
141154
}
142155

143156
/**
144-
* Creates a {@code RemoteGcsHelper} object using default project id and authentication
145-
* credentials.
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
146164
*/
147165
public static RemoteGcsHelper create() throws GcsHelperException {
148-
StorageOptions storageOptions = StorageOptions.builder()
149-
.retryParams(retryParams())
150-
.connectTimeout(60000)
151-
.readTimeout(60000)
152-
.build();
153-
return new RemoteGcsHelper(storageOptions);
154-
}
155-
156-
private static RetryParams retryParams() {
157-
return RetryParams.builder()
158-
.retryMaxAttempts(10)
159-
.retryMinAttempts(6)
160-
.maxRetryDelayMillis(30000)
161-
.totalRetryPeriodMillis(120000)
162-
.initialRetryDelayMillis(250)
163-
.build();
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);
164183
}
165184

166185
private static class DeleteBucketTask implements Callable<Boolean> {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Export test env variables
2-
export GCLOUD_PROJECT="gcloud-devel"
3-
export GOOGLE_APPLICATION_CREDENTIALS=$TRAVIS_BUILD_DIR/signing-tools/gcloud-devel-travis.json
2+
export GCLOUD_TESTS_PROJECT_ID="gcloud-devel"
3+
export GCLOUD_TESTS_KEY=$TRAVIS_BUILD_DIR/signing-tools/gcloud-devel-travis.json

0 commit comments

Comments
 (0)