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

CredentialOptions#jsonCredentials(InputStream) requires the InputStream to be open until it's used in BigtableSession #534

Closed
udoprog opened this issue Oct 22, 2015 · 0 comments
Assignees
Labels
api: bigtable Issues related to the googleapis/java-bigtable-hbase API.

Comments

@udoprog
Copy link
Contributor

udoprog commented Oct 22, 2015

When setting up credentials with CredentialOptions#jsonCredentials(InputStream) I was suprised to see that the resulting CredentialOptions require the InputStream to be open.

My code uses an abstraction to setup CredentialOptions instances. The class itself does not expose any statefullness (i.e. isReadable(), close()) meaning there's no reasonable way for a user of an CredentialOptions instance to check if it's readable or not.

I'd prefer if CredentialOptions.jsonCredentials(InputStream) fully read and parsed the given InputStream, and stored the credentials in memory, this would allow for patterns like the following to safely work without leaking an open InputStream.

public CredentialOptions buildCredentials() throws IOException {
    try (final InputStream in = Files.newInputStream(...)) {
        return CredentialOptions.jsonCredentials(in);
    }
}

The kind of exceptions you'll see otherwise are the following:

java.nio.channels.ClosedChannelException
        at sun.nio.ch.FileChannelImpl.ensureOpen(FileChannelImpl.java:110)
        at sun.nio.ch.FileChannelImpl.read(FileChannelImpl.java:147)
        at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:65)
        at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:109)
        at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:103)
        at com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.ensureLoaded(ByteSourceJsonBootstrapper.java:489)
        at com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.detectEncoding(ByteSourceJsonBootstrapper.java:126)
        at com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper.constructParser(ByteSourceJsonBootstrapper.java:215)
        at com.fasterxml.jackson.core.JsonFactory._createParser(JsonFactory.java:1240)
        at com.fasterxml.jackson.core.JsonFactory.createParser(JsonFactory.java:802)
        at com.fasterxml.jackson.core.JsonFactory.createJsonParser(JsonFactory.java:972)
        at com.google.api.client.json.jackson2.JacksonFactory.createJsonParser(JacksonFactory.java:93)
        at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:85)
        at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81)
        at com.google.auth.oauth2.GoogleCredentials.fromStream(GoogleCredentials.java:101)
        at com.google.cloud.bigtable.config.CredentialFactory.getInputStreamCredential(CredentialFactory.java:182)
        at com.google.cloud.bigtable.config.CredentialFactory.getCredentials(CredentialFactory.java:108)
        at com.google.cloud.bigtable.grpc.BigtableSession$4.call(BigtableSession.java:249)
        at com.google.cloud.bigtable.grpc.BigtableSession$4.call(BigtableSession.java:246)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
sduskis added a commit to sduskis/cloud-bigtable-client that referenced this issue Oct 30, 2015
@sduskis sduskis self-assigned this Oct 30, 2015
@sduskis sduskis closed this as completed Nov 2, 2015
@google-cloud-label-sync google-cloud-label-sync bot added the api: bigtable Issues related to the googleapis/java-bigtable-hbase API. label Jan 31, 2020
yoshi-automation added a commit that referenced this issue May 26, 2020
Co-authored-by: Jeff Ching <chingor@google.com>
Co-authored-by: Jeffrey Rennie <rennie@google.com>

Source-Author: Brian Chen <chenbrian@google.com>
Source-Date: Tue May 12 10:24:59 2020 -0700
Source-Repo: googleapis/synthtool
Source-Sha: 5b48b0716a36ca069db3038da7e205c87a22ed19
Source-Link: googleapis/synthtool@5b48b07
yoshi-automation added a commit that referenced this issue Jun 2, 2020
Co-authored-by: Jeff Ching <chingor@google.com>
Co-authored-by: Jeffrey Rennie <rennie@google.com>

Source-Author: Brian Chen <chenbrian@google.com>
Source-Date: Tue May 12 10:24:59 2020 -0700
Source-Repo: googleapis/synthtool
Source-Sha: 5b48b0716a36ca069db3038da7e205c87a22ed19
Source-Link: googleapis/synthtool@5b48b07
kolea2 pushed a commit that referenced this issue Jun 3, 2020
Co-authored-by: Jeff Ching <chingor@google.com>
Co-authored-by: Jeffrey Rennie <rennie@google.com>

Source-Author: Brian Chen <chenbrian@google.com>
Source-Date: Tue May 12 10:24:59 2020 -0700
Source-Repo: googleapis/synthtool
Source-Sha: 5b48b0716a36ca069db3038da7e205c87a22ed19
Source-Link: googleapis/synthtool@5b48b07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigtable Issues related to the googleapis/java-bigtable-hbase API.
Projects
None yet
Development

No branches or pull requests

2 participants