Skip to content

Commit d3ecfdb

Browse files
committed
---
yaml --- r: 1951 b: refs/heads/pubsub-alpha c: 82ebc71 h: refs/heads/master i: 1949: 9eb95f7 1947: 7265c86 1943: 2affb64 1935: 0a132c9 1919: 381e89d
1 parent 19b9c0d commit d3ecfdb

3 files changed

Lines changed: 23 additions & 5 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: c3b6616c98982a201c1dcd6a5b1e7d3210d009d6
6+
refs/heads/pubsub-alpha: 82ebc7128133d7727eec8e85df927ec9599205f8
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
88
refs/heads/update-datastore: 482954f2c5055231e5b3122ea91d2ba00ce8187c
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
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;
3132

3233
import java.io.IOException;
3334
import java.io.InputStream;
@@ -212,7 +213,7 @@ public RestorableState<AuthCredentials> capture() {
212213
}
213214
}
214215

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

217218
private GoogleCredentials googleCredentials;
218219

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

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+
258268
@Override
259269
public RestorableState<AuthCredentials> capture() {
260270
return STATE;

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
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;
4648
import com.google.gcloud.AuthCredentials.ServiceAccountAuthCredentials;
4749
import com.google.gcloud.PageImpl;
4850
import com.google.gcloud.BaseService;
@@ -584,9 +586,15 @@ public URL signUrl(BlobInfo blobInfo, long duration, TimeUnit unit, SignUrlOptio
584586
ServiceAccountAuthCredentials cred =
585587
(ServiceAccountAuthCredentials) optionMap.get(SignUrlOption.Option.SERVICE_ACCOUNT_CRED);
586588
if (cred == null) {
587-
checkArgument(options().authCredentials() instanceof ServiceAccountAuthCredentials,
588-
"Signing key was not provided and could not be derived");
589-
cred = (ServiceAccountAuthCredentials) this.options().authCredentials();
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");
590598
}
591599
// construct signature - see https://cloud.google.com/storage/docs/access-control#Signed-URLs
592600
StringBuilder stBuilder = new StringBuilder();

0 commit comments

Comments
 (0)