@@ -84,7 +84,6 @@ public abstract class ServiceOptions<ServiceT extends Service<OptionsT>, Service
8484 private final String serviceRpcFactoryClassName ;
8585 private final String serviceFactoryClassName ;
8686 private final Clock clock ;
87- private final boolean noCredentials ;
8887 private final Credentials credentials ;
8988
9089 private transient ServiceRpcFactory <ServiceRpcT , OptionsT > serviceRpcFactory ;
@@ -106,7 +105,6 @@ protected abstract static class Builder<ServiceT extends Service<OptionsT>, Serv
106105
107106 private String projectId ;
108107 private String host ;
109- private boolean noCredentials ;
110108 private Credentials credentials ;
111109 private RetryParams retryParams ;
112110 private ServiceFactory <ServiceT , OptionsT > serviceFactory ;
@@ -118,7 +116,6 @@ protected Builder() {}
118116 protected Builder (ServiceOptions <ServiceT , ServiceRpcT , OptionsT > options ) {
119117 projectId = options .projectId ;
120118 host = options .host ;
121- noCredentials = options .noCredentials ;
122119 credentials = options .credentials ;
123120 retryParams = options .retryParams ;
124121 serviceFactory = options .serviceFactory ;
@@ -214,29 +211,18 @@ public B setHost(String host) {
214211 }
215212
216213 /**
217- * Sets the service authentication credentials. If this method or {@link #setNoCredentials() are
218- * not used on the builder, {@link GoogleCredentials#getApplicationDefault()} will be used to
219- * attempt getting credentials from the environment.
214+ * Sets the service authentication credentials. If no credentials are set,
215+ * {@link GoogleCredentials#getApplicationDefault()} will be used to attempt getting credentials
216+ * from the environment. Use {@link NoCredentials#getInstance()} to skip authentication, this is
217+ * typically useful when using local service emulators.
220218 *
221219 * @param credentials authentication credentials, should not be {@code null}
222220 * @return the builder
223221 * @throws NullPointerException if {@code credentials} is {@code null}. To disable
224- * authentication use {@link Builder#setNoCredentials ()}
222+ * authentication use {@link NoCredentials#getInstance ()}
225223 */
226224 public B setCredentials (Credentials credentials ) {
227225 this .credentials = checkNotNull (credentials );
228- this .noCredentials = false ;
229- return self ();
230- }
231-
232- /**
233- * Sets that no credentials should be used. This is typically useful when using the local
234- * service emulators, such as {@code LocalDatastoreHelper}, {@code LocalPubsubHelper} and
235- * {@code LocalResourceManagerHelper}.
236- */
237- public B setNoCredentials () {
238- this .noCredentials = true ;
239- this .credentials = null ;
240226 return self ();
241227 }
242228
@@ -296,9 +282,7 @@ protected ServiceOptions(Class<? extends ServiceFactory<ServiceT, OptionsT>> ser
296282 + "or the environment. Please set a project ID using the builder." );
297283 }
298284 host = firstNonNull (builder .host , getDefaultHost ());
299- noCredentials = builder .noCredentials ;
300- credentials = builder .credentials != null || noCredentials
301- ? builder .credentials : defaultCredentials ();
285+ credentials = builder .credentials != null ? builder .credentials : defaultCredentials ();
302286 retryParams = firstNonNull (builder .retryParams , defaultRetryParams ());
303287 serviceFactory = firstNonNull (builder .serviceFactory ,
304288 getFromServiceLoader (serviceFactoryClass , getDefaultServiceFactory ()));
@@ -540,8 +524,8 @@ public Credentials getCredentials() {
540524 */
541525 public Credentials getScopedCredentials () {
542526 Credentials credentialsToReturn = credentials ;
543- if (credentials instanceof GoogleCredentials &&
544- ((GoogleCredentials ) credentials ).createScopedRequired ()) {
527+ if (credentials instanceof GoogleCredentials
528+ && ((GoogleCredentials ) credentials ).createScopedRequired ()) {
545529 credentialsToReturn = ((GoogleCredentials ) credentials ).createScoped (getScopes ());
546530 }
547531 return credentialsToReturn ;
@@ -626,13 +610,12 @@ public String getLibraryVersion() {
626610 }
627611
628612 protected int baseHashCode () {
629- return Objects .hash (projectId , host , noCredentials , credentials , retryParams ,
630- serviceFactoryClassName , serviceRpcFactoryClassName , clock );
613+ return Objects .hash (projectId , host , credentials , retryParams , serviceFactoryClassName ,
614+ serviceRpcFactoryClassName , clock );
631615 }
632616
633617 protected boolean baseEquals (ServiceOptions <?, ?, ?> other ) {
634- return noCredentials == other .noCredentials
635- && Objects .equals (projectId , other .projectId )
618+ return Objects .equals (projectId , other .projectId )
636619 && Objects .equals (host , other .host )
637620 && Objects .equals (credentials , other .credentials )
638621 && Objects .equals (retryParams , other .retryParams )
0 commit comments