Skip to content

Commit 6ee3aa4

Browse files
committed
---
yaml --- r: 6529 b: refs/heads/tswast-patch-1 c: 82ebc71 h: refs/heads/master i: 6527: 81ca046
1 parent a861ab1 commit 6ee3aa4

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
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: c3b6616c98982a201c1dcd6a5b1e7d3210d009d6
60+
refs/heads/tswast-patch-1: 82ebc7128133d7727eec8e85df927ec9599205f8
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/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/tswast-patch-1/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)