io.github.qsy7.google.CredentialsProvider Maven / Gradle / Ivy
The newest version!
package io.github.qsy7.google;
import com.google.auth.oauth2.ServiceAccountCredentials;
import io.github.qsy7.google.property.GoogleCloudAccessToken;
import io.github.qsy7.property.api.annotation.Property;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import jakarta.inject.Inject;
import jakarta.inject.Provider;
public class CredentialsProvider implements Provider {
protected final ServiceAccountCredentials credentials;
@Inject
public CredentialsProvider(
@Property(GoogleCloudAccessToken.class) String googleCloudAccessTokenFilename)
throws IOException {
credentials =
ServiceAccountCredentials.fromStream(
new BufferedInputStream(new FileInputStream(googleCloudAccessTokenFilename)));
}
@Override
public ServiceAccountCredentials get() {
return credentials;
}
}