Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow services to avoid setting project ID #346

Merged
merged 2 commits into from
Nov 10, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);

This comment was marked as spam.

This comment was marked as spam.

}
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() {

This comment was marked as spam.

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