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

Enable running against gcloud datastore emulator (using DATASTORE_HOST) #141

Merged
merged 2 commits into from
Aug 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -154,7 +154,7 @@ public B serviceRpcFactory(ServiceRpcFactory<ServiceRpcT, OptionsT> serviceRpcFa

protected ServiceOptions(Builder<ServiceRpcT, OptionsT, ?> builder) {
projectId = checkNotNull(builder.projectId != null ? builder.projectId : defaultProject());
host = firstNonNull(builder.host, DEFAULT_HOST);
host = firstNonNull(builder.host, defaultHost());
httpTransportFactory =
firstNonNull(builder.httpTransportFactory, DefaultHttpTransportFactory.INSTANCE);
authCredentials = firstNonNull(builder.authCredentials, defaultAuthCredentials());
Expand Down Expand Up @@ -191,6 +191,10 @@ protected static String appEngineAppId() {
return System.getProperty("com.google.appengine.application.id");
}

protected String defaultHost() {
return DEFAULT_HOST;
}

protected String defaultProject() {
String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME));
if (projectId == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class DatastoreOptions extends ServiceOptions<DatastoreRpc, DatastoreOpti

private static final long serialVersionUID = -8636602944160689193L;
private static final String DATASET_ENV_NAME = "DATASTORE_DATASET";
private static final String HOST_ENV_NAME = "DATASTORE_HOST";
private static final String DATASTORE_SCOPE = "https://www.googleapis.com/auth/datastore";
private static final String USERINFO_SCOPE = "https://www.googleapis.com/auth/userinfo.email";
private static final Set<String> SCOPES = ImmutableSet.of(DATASTORE_SCOPE, USERINFO_SCOPE);
Expand Down Expand Up @@ -122,6 +123,12 @@ private DatastoreOptions normalize() {
}
}

@Override
protected String defaultHost() {
String host = System.getProperty(HOST_ENV_NAME, System.getenv(HOST_ENV_NAME));
return host != null ? host : super.defaultHost();
}

@Override
protected String defaultProject() {
String projectId = System.getProperty(DATASET_ENV_NAME, System.getenv(DATASET_ENV_NAME));
Expand Down