Use Emulator Credentials when using Firestore Emulator
See original GitHub issuedescribe the problem When trying to run CI/CD against a Firestore emulator instance (e.g. in GitHub Actions), tests were failing due to not finding the GOOGLE_APPLICATION_CREDENTIALS location. This was unexpected since we’d configured emulator=true, and it ofc wasn’t caught because we all have this already set on our local machines.
spring.cloud.gcp.firestore.emulator.enabled=true
spring.cloud.gcp.firestore.host-port=localhost:1234
spring.cloud.gcp.project-id=emulator
So, the workaround was to override the CredentialsProvider to explicitly use FirestoreOptions.EmulatorCredentials()
:
import com.google.api.gax.core.CredentialsProvider;
import com.google.auth.Credentials;
import com.google.cloud.firestore.FirestoreOptions;
//
@Configuration
public class SomeConfiguration {
@Profile("integration-test")
@Primary
@Bean
CredentialsProvider credentialsProvider() {
return new CredentialsProvider() {
@Override
public Credentials getCredentials() throws IOException {
return new FirestoreOptions.EmulatorCredentials();
}
};
}
}
Describe the solution you’d like It’d be nice if this worked without further configuration; e.g. if CredentialsProvider used emulator credentials when emulator is enabled.
Describe alternatives you’ve considered I see in the source that CredentialsProvider always pulls from the location on the Credentials object, which makes sense since a lot of the GCP components don’t have emulator support. Might be tricky, if you don’t want to add some lines to check typeof Credentials.
Additional context None
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (11 by maintainers)
Top GitHub Comments
Great point about impacting other services! You’re welcome to work on it. I just realized that we have already solved this problem in Pub/Sub. So, we don’t have to reinvent the solution. In Pub/Sub, we made
GcpPubSubAutoConfiguration
aware of the emulator setting. See this snippet:A similar approach should work in the Firestore module. WDYT?
Cool, look good to me. Let me try to follow the
GcpPubSubAutoConfiguration
and add the same handling to Firestore emulator.