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: [vertexai] Use default scopes from Prediction Service to create application default credentials if scopes are empty. #10169

Merged
merged 3 commits into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.vertexai.api.PredictionServiceClient;
import com.google.cloud.vertexai.api.PredictionServiceSettings;
import com.google.cloud.vertexai.api.stub.PredictionServiceStubSettings;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -87,9 +89,11 @@ public VertexAI(String projectId, String location, String... scopes) throws IOEx
Logger logger = Logger.getLogger("com.google.auth.oauth2.DefaultCredentialsProvider");
Level previousLevel = logger.getLevel();
logger.setLevel(Level.SEVERE);
List<String> defaultScopes =
PredictionServiceStubSettings.defaultCredentialsProviderBuilder().getScopesToApply();
GoogleCredentials credentials =
scopes.length == 0
? GoogleCredentials.getApplicationDefault()
? GoogleCredentials.getApplicationDefault().createScoped(defaultScopes)
: GoogleCredentials.getApplicationDefault().createScoped(scopes);
logger.setLevel(previousLevel);

Expand Down
Loading