googleapis / googleapis/google-cloud-java

[java-firestore] Ability to set emulator host/port from .setHost rather than env var

Đang mở
#13,143 8 bình luận 0 reaction 0 người được giao Xem trên GitHub
api: firestore type: feature request
Ngôn ngữ chính
Java
Star
2.1k
Fork
1.2k
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
154

Mô tả

#### Environment details

1. OSX, Java

#### Steps to reproduce

1. To use Testcontainer + Firestore emulator is extremely difficult.

#### Code example
Firestore client library can only connect to a firestore emulator by using an env var. This is not idiomatic for Java unit tests.

it's impossible to set the emulator host/port simply from `.setHost(..)`
```java
FirestoreOptions firestoreOptions =
FirestoreOptions.newBuilder().setHost(...).
```

The real code is this:
```java
// duplicate the FakeCredentials class because it's package protected and not publicly accessible.
static class FakeCredentials extends Credentials {
private final Map> HEADERS =
ImmutableMap.of("Authorization", Arrays.asList("Bearer owner"));
...
}

// then, duplicate the code that otherwise executes from an env var:
FirestoreOptions firestoreOptions =
FirestoreOptions.newBuilder()
.setProjectId(FIRESTORE_PROJECT_ID)
.setChannelProvider(
InstantiatingGrpcChannelProvider.newBuilder()
.setEndpoint(
String.format(
"%s:%d",
FIRESTORE_CONTAINER.getContainerIpAddress(),
FIRESTORE_CONTAINER.getMappedPort(8080)))
.setChannelConfigurator(
(managedChannelBuilder -> managedChannelBuilder.usePlaintext()))
.build())
.setCredentialsProvider(FixedCredentialsProvider.create(new FakeCredentials()))
.build();

```

#### Any additional information below
It'd be MUCH easier if emulator host/port can simply be set via .setHost(...), OR, a convenience method, such as .useEmulator(host, port)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.