Skip to content
Merged
Changes from all commits
Commits
File filter

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 @@ -60,6 +60,7 @@ public final class FirestoreOptions extends ServiceOptions<Firestore, FirestoreO
private final String databaseId;
private final TransportChannelProvider channelProvider;
private final CredentialsProvider credentialsProvider;
private final String emulatorHost;

public static class DefaultFirestoreFactory implements FirestoreFactory {

Expand Down Expand Up @@ -114,11 +115,16 @@ public TransportChannelProvider getTransportChannelProvider() {
return channelProvider;
}

public String getEmulatorHost() {
return emulatorHost;
}

public static class Builder extends ServiceOptions.Builder<Firestore, FirestoreOptions, Builder> {

@Nullable private String databaseId = null;
@Nullable private TransportChannelProvider channelProvider = null;
@Nullable private CredentialsProvider credentialsProvider = null;
@Nullable private String emulatorHost = null;

private Builder() {}

Expand All @@ -127,6 +133,7 @@ private Builder(FirestoreOptions options) {
this.databaseId = options.databaseId;
this.channelProvider = options.channelProvider;
this.credentialsProvider = options.credentialsProvider;
this.emulatorHost = options.emulatorHost;
}

/**
Expand Down Expand Up @@ -174,6 +181,17 @@ public Builder setCredentialsProvider(@Nonnull CredentialsProvider credentialsPr
return this;
}

/**
* Sets the emulator host to use with this Firestore client. The value passed to this method
* will take precedent if the {@code FIRESTORE_EMULATOR_HOST} environment variable is also set.
*
* @param emulatorHost The Firestore emulator host to use with this client.
*/
public Builder setEmulatorHost(@Nonnull String emulatorHost) {
this.emulatorHost = emulatorHost;
return this;
}

/**
* Sets the database ID to use with this Firestore client.
*
Expand All @@ -196,7 +214,9 @@ public FirestoreOptions build() {
}

// Override credentials and channel provider if we are using the emulator.
String emulatorHost = System.getenv(FIRESTORE_EMULATOR_SYSTEM_VARIABLE);
if (emulatorHost == null) {
emulatorHost = System.getenv(FIRESTORE_EMULATOR_SYSTEM_VARIABLE);
}
if (emulatorHost != null) {
// Try creating a host in order to validate that the host name is valid.
try {
Expand Down Expand Up @@ -280,6 +300,8 @@ protected FirestoreOptions(Builder builder) {
builder.credentialsProvider != null
? builder.credentialsProvider
: GrpcTransportOptions.setUpCredentialsProvider(this);

this.emulatorHost = builder.emulatorHost;
}

private static class FirestoreDefaults implements ServiceDefaults<Firestore, FirestoreOptions> {
Expand Down