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

fix: refactor FakeCredentials #325

Merged
merged 1 commit into from Aug 11, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions google-cloud-firestore/clirr-ignored-differences.xml
Expand Up @@ -157,4 +157,14 @@
<to>com.google.cloud.firestore.CollectionGroup</to>
</difference>

<!--
FakeCredentials Refactor
com.google.cloud.firestore.FirestoreOptions$Builder$FakeCredentials -> com.google.cloud.firestore.FirestoreOptions$EmulatorCredentials
-->
<difference>
<differenceType>8001</differenceType>
<className>com/google/cloud/firestore/FirestoreOptions$Builder$FakeCredentials</className>
<to>*</to>
</difference>

</differences>
Expand Up @@ -231,39 +231,39 @@ public ManagedChannelBuilder apply(ManagedChannelBuilder input) {
.build());
// Use a `CredentialProvider` to match the Firebase Admin SDK, which prevents the Admin SDK
// from overwriting the Emulator credentials.
this.setCredentialsProvider(FixedCredentialsProvider.create(new FakeCredentials()));
this.setCredentialsProvider(FixedCredentialsProvider.create(new EmulatorCredentials()));
}

return new FirestoreOptions(this);
}
}

public class FakeCredentials extends Credentials {
private final Map<String, List<String>> HEADERS =
ImmutableMap.of("Authorization", Arrays.asList("Bearer owner"));

@Override
public String getAuthenticationType() {
throw new IllegalArgumentException("Not supported");
}
public static class EmulatorCredentials extends Credentials {
private final Map<String, List<String>> HEADERS =
ImmutableMap.of("Authorization", Arrays.asList("Bearer owner"));

@Override
public Map<String, List<String>> getRequestMetadata(URI uri) {
return HEADERS;
}
@Override
public String getAuthenticationType() {
throw new IllegalArgumentException("Not supported");
}

@Override
public boolean hasRequestMetadata() {
return true;
}
@Override
public Map<String, List<String>> getRequestMetadata(URI uri) {
return HEADERS;
}

@Override
public boolean hasRequestMetadataOnly() {
return true;
}
@Override
public boolean hasRequestMetadata() {
return true;
}

@Override
public void refresh() {}
@Override
public boolean hasRequestMetadataOnly() {
return true;
}

@Override
public void refresh() {}
}

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