Skip to content

Commit 269e62c

Browse files
authored
fix: refactor FakeCredentials (#325)
This change allows users who want to try to manually configured FirestoreOptions for an emulator to be able to leverage the credentials we use when boostrapping via environment variable. * Rename FakeCredentials to EmulatorCredentials * Make EmulatorCredentials static * Move from inner class of FirestoreOptions.Builder to inner class of FirestoreOptions Related to #190
1 parent 854968f commit 269e62c

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

google-cloud-firestore/clirr-ignored-differences.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,14 @@
162162
<to>com.google.cloud.firestore.CollectionGroup</to>
163163
</difference>
164164

165+
<!--
166+
FakeCredentials Refactor
167+
com.google.cloud.firestore.FirestoreOptions$Builder$FakeCredentials -> com.google.cloud.firestore.FirestoreOptions$EmulatorCredentials
168+
-->
169+
<difference>
170+
<differenceType>8001</differenceType>
171+
<className>com/google/cloud/firestore/FirestoreOptions$Builder$FakeCredentials</className>
172+
<to>*</to>
173+
</difference>
174+
165175
</differences>

google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreOptions.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -226,39 +226,39 @@ public ManagedChannelBuilder apply(ManagedChannelBuilder input) {
226226
.build());
227227
// Use a `CredentialProvider` to match the Firebase Admin SDK, which prevents the Admin SDK
228228
// from overwriting the Emulator credentials.
229-
this.setCredentialsProvider(FixedCredentialsProvider.create(new FakeCredentials()));
229+
this.setCredentialsProvider(FixedCredentialsProvider.create(new EmulatorCredentials()));
230230
}
231231

232232
return new FirestoreOptions(this);
233233
}
234+
}
234235

235-
public class FakeCredentials extends Credentials {
236-
private final Map<String, List<String>> HEADERS =
237-
ImmutableMap.of("Authorization", Arrays.asList("Bearer owner"));
238-
239-
@Override
240-
public String getAuthenticationType() {
241-
throw new IllegalArgumentException("Not supported");
242-
}
236+
public static class EmulatorCredentials extends Credentials {
237+
private final Map<String, List<String>> HEADERS =
238+
ImmutableMap.of("Authorization", Arrays.asList("Bearer owner"));
243239

244-
@Override
245-
public Map<String, List<String>> getRequestMetadata(URI uri) {
246-
return HEADERS;
247-
}
240+
@Override
241+
public String getAuthenticationType() {
242+
throw new IllegalArgumentException("Not supported");
243+
}
248244

249-
@Override
250-
public boolean hasRequestMetadata() {
251-
return true;
252-
}
245+
@Override
246+
public Map<String, List<String>> getRequestMetadata(URI uri) {
247+
return HEADERS;
248+
}
253249

254-
@Override
255-
public boolean hasRequestMetadataOnly() {
256-
return true;
257-
}
250+
@Override
251+
public boolean hasRequestMetadata() {
252+
return true;
253+
}
258254

259-
@Override
260-
public void refresh() {}
255+
@Override
256+
public boolean hasRequestMetadataOnly() {
257+
return true;
261258
}
259+
260+
@Override
261+
public void refresh() {}
262262
}
263263

264264
@InternalApi("This class should only be extended within google-cloud-java")

0 commit comments

Comments
 (0)