Skip to content

Commit c5e85a1

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 6577 b: refs/heads/tswast-patch-1 c: b5c1cae h: refs/heads/master i: 6575: 52004cf
1 parent 14a786a commit c5e85a1

6 files changed

Lines changed: 16 additions & 32 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: 57d6e3f6eac16397fdef7ffc30b022b4faaf2a24
60+
refs/heads/tswast-patch-1: b5c1caec2a3d1cfe5a0b7a118154b3e333471b6f
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-core/src/main/java/com/google/gcloud/AuthCredentials.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ public static class ServiceAccountAuthCredentials extends AuthCredentials {
136136
private final String account;
137137
private final PrivateKey privateKey;
138138

139-
private static final AuthCredentials NO_CREDENTIALS = new ServiceAccountAuthCredentials();
140-
141139
private static class ServiceAccountAuthCredentialsState
142140
implements RestorableState<AuthCredentials>, Serializable {
143141

@@ -153,9 +151,6 @@ private ServiceAccountAuthCredentialsState(String account, PrivateKey privateKey
153151

154152
@Override
155153
public AuthCredentials restore() {
156-
if (account == null && privateKey == null) {
157-
return NO_CREDENTIALS;
158-
}
159154
return new ServiceAccountAuthCredentials(account, privateKey);
160155
}
161156

@@ -180,16 +175,9 @@ public boolean equals(Object obj) {
180175
this.privateKey = checkNotNull(privateKey);
181176
}
182177

183-
ServiceAccountAuthCredentials() {
184-
account = null;
185-
privateKey = null;
186-
}
187-
188178
@Override
189179
protected GoogleCredentials credentials() {
190-
return (privateKey == null)
191-
? new GoogleCredentials(null)
192-
: new ServiceAccountCredentials(null, account, privateKey, null, null);
180+
return new ServiceAccountCredentials(null, account, privateKey, null, null);
193181
}
194182

195183
public String account() {
@@ -327,8 +315,4 @@ public static ServiceAccountAuthCredentials createForJson(InputStream jsonCreden
327315
"The given JSON Credentials Stream is not a service account credential.");
328316
}
329317
}
330-
331-
public static AuthCredentials noCredentials() {
332-
return ServiceAccountAuthCredentials.NO_CREDENTIALS;
333-
}
334318
}

branches/tswast-patch-1/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,9 @@ protected ServiceOptions(Class<? extends ServiceFactory<ServiceT, OptionsT>> ser
312312
httpTransportFactory = firstNonNull(builder.httpTransportFactory,
313313
getFromServiceLoader(HttpTransportFactory.class, DefaultHttpTransportFactory.INSTANCE));
314314
httpTransportFactoryClassName = httpTransportFactory.getClass().getName();
315-
authCredentials = firstNonNull(builder.authCredentials, defaultAuthCredentials());
316-
authCredentialsState = authCredentials.capture();
315+
authCredentials =
316+
builder.authCredentials != null ? builder.authCredentials : defaultAuthCredentials();
317+
authCredentialsState = authCredentials != null ? authCredentials.capture() : null;
317318
retryParams = builder.retryParams;
318319
serviceFactory = firstNonNull(builder.serviceFactory,
319320
getFromServiceLoader(serviceFactoryClass, defaultServiceFactory()));
@@ -349,7 +350,7 @@ private static AuthCredentials defaultAuthCredentials() {
349350
try {
350351
return AuthCredentials.createApplicationDefaults();
351352
} catch (Exception ex) {
352-
return AuthCredentials.noCredentials();
353+
return null;
353354
}
354355
}
355356

@@ -509,12 +510,15 @@ public RetryParams retryParams() {
509510
* options.
510511
*/
511512
public HttpRequestInitializer httpRequestInitializer() {
512-
final HttpRequestInitializer baseRequestInitializer =
513-
new HttpCredentialsAdapter(authCredentials().credentials().createScoped(scopes()));
513+
final HttpRequestInitializer delegate = authCredentials() != null
514+
? new HttpCredentialsAdapter(authCredentials().credentials().createScoped(scopes()))
515+
: null;
514516
return new HttpRequestInitializer() {
515517
@Override
516518
public void initialize(HttpRequest httpRequest) throws IOException {
517-
baseRequestInitializer.initialize(httpRequest);
519+
if (delegate != null) {
520+
delegate.initialize(httpRequest);
521+
}
518522
if (connectTimeout >= 0) {
519523
httpRequest.setConnectTimeout(connectTimeout);
520524
}
@@ -580,7 +584,7 @@ private void readObject(ObjectInputStream input) throws IOException, ClassNotFou
580584
httpTransportFactory = newInstance(httpTransportFactoryClassName);
581585
serviceFactory = newInstance(serviceFactoryClassName);
582586
serviceRpcFactory = newInstance(serviceRpcFactoryClassName);
583-
authCredentials = authCredentialsState.restore();
587+
authCredentials = authCredentialsState != null ? authCredentialsState.restore() : null;
584588
}
585589

586590
private static <T> T newInstance(String className) throws IOException, ClassNotFoundException {

branches/tswast-patch-1/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/SerializationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public void testServiceOptions() throws Exception {
144144
options = options.toBuilder()
145145
.namespace("ns1")
146146
.retryParams(RetryParams.defaultInstance())
147-
.authCredentials(AuthCredentials.noCredentials())
147+
.authCredentials(null)
148148
.force(true)
149149
.build();
150150
serializedCopy = serializeAndDeserialize(options);

branches/tswast-patch-1/gcloud-java-storage/src/test/java/com/google/gcloud/storage/SerializationTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void testServiceOptions() throws Exception {
8383
options = options.toBuilder()
8484
.projectId("p2")
8585
.retryParams(RetryParams.defaultInstance())
86-
.authCredentials(AuthCredentials.noCredentials())
86+
.authCredentials(null)
8787
.pathDelimiter(":")
8888
.build();
8989
serializedCopy = serializeAndDeserialize(options);
@@ -111,7 +111,6 @@ public void testReadChannelState() throws IOException, ClassNotFoundException {
111111
StorageOptions options = StorageOptions.builder()
112112
.projectId("p2")
113113
.retryParams(RetryParams.defaultInstance())
114-
.authCredentials(AuthCredentials.noCredentials())
115114
.build();
116115
BlobReadChannel reader =
117116
new BlobReadChannelImpl(options, BlobId.of("b", "n"), EMPTY_RPC_OPTIONS);
@@ -127,7 +126,6 @@ public void testWriteChannelState() throws IOException, ClassNotFoundException {
127126
StorageOptions options = StorageOptions.builder()
128127
.projectId("p2")
129128
.retryParams(RetryParams.defaultInstance())
130-
.authCredentials(AuthCredentials.noCredentials())
131129
.build();
132130
BlobWriteChannelImpl writer = new BlobWriteChannelImpl(
133131
options, BlobInfo.builder(BlobId.of("b", "n")).build(), "upload-id");

branches/tswast-patch-1/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@
3131
import com.google.common.collect.Iterables;
3232
import com.google.common.collect.Maps;
3333
import com.google.common.io.BaseEncoding;
34-
import com.google.gcloud.AuthCredentials;
3534
import com.google.gcloud.AuthCredentials.ServiceAccountAuthCredentials;
35+
import com.google.gcloud.Page;
3636
import com.google.gcloud.RetryParams;
3737
import com.google.gcloud.ServiceOptions;
38-
import com.google.gcloud.Page;
3938
import com.google.gcloud.spi.StorageRpc;
4039
import com.google.gcloud.spi.StorageRpc.Tuple;
4140
import com.google.gcloud.spi.StorageRpcFactory;
@@ -260,7 +259,6 @@ public void setUp() throws IOException, InterruptedException {
260259
EasyMock.replay(rpcFactoryMock);
261260
options = StorageOptions.builder()
262261
.projectId("projectId")
263-
.authCredentials(AuthCredentials.noCredentials())
264262
.clock(TIME_SOURCE)
265263
.serviceRpcFactory(rpcFactoryMock)
266264
.build();

0 commit comments

Comments
 (0)