Skip to content

Commit 717c839

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 1999 b: refs/heads/pubsub-alpha c: b5c1cae h: refs/heads/master i: 1997: 3e9de2c 1995: 5772968 1991: 3fb9b3a 1983: 5b9e6e5
1 parent e48994e commit 717c839

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
@@ -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: 57d6e3f6eac16397fdef7ffc30b022b4faaf2a24
6+
refs/heads/pubsub-alpha: b5c1caec2a3d1cfe5a0b7a118154b3e333471b6f
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: 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/pubsub-alpha/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/pubsub-alpha/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/pubsub-alpha/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/pubsub-alpha/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)