Skip to content

Commit

Permalink
Allow services to avoid setting project ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajay Kannan committed Nov 10, 2015
1 parent 54b8472 commit ad12f41
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,10 @@ public B readTimeout(int readTimeout) {
protected ServiceOptions(Class<? extends ServiceFactory<ServiceT, OptionsT>> serviceFactoryClass,
Class<? extends ServiceRpcFactory<ServiceRpcT, OptionsT>> rpcFactoryClass,
Builder<ServiceT, ServiceRpcT, OptionsT, ?> builder) {
projectId = checkNotNull(builder.projectId != null ? builder.projectId : defaultProject());
projectId = builder.projectId != null ? builder.projectId : defaultProject();
if (projectIdRequired()) {
checkNotNull(projectId);
}
host = firstNonNull(builder.host, defaultHost());
httpTransportFactory = firstNonNull(builder.httpTransportFactory,
getFromServiceLoader(HttpTransportFactory.class, DefaultHttpTransportFactory.INSTANCE));
Expand All @@ -325,6 +328,16 @@ protected ServiceOptions(Class<? extends ServiceFactory<ServiceT, OptionsT>> ser
clock = firstNonNull(builder.clock, Clock.defaultClock());
}

/**
* Returns whether a service requires a project ID. This method may be overridden in
* service-specific Options objects.
*
* @return true if a project ID is required to use the service, false if not.
*/
public boolean projectIdRequired() {
return true;
}

private static AuthCredentials defaultAuthCredentials() {
// Consider App Engine. This will not be needed once issue #21 is fixed.
if (appEngineAppId() != null) {
Expand Down Expand Up @@ -462,6 +475,8 @@ public ServiceRpcT rpc() {

/**
* Returns the project id.
*
* Return value can be null (for services that don't require a project id).
*/
public String projectId() {
return projectId;
Expand Down

0 comments on commit ad12f41

Please sign in to comment.