Skip to content

Commit

Permalink
fix: [vertexai] Use default scopes from Prediction Service to create …
Browse files Browse the repository at this point in the history
…application default credentials if scopes are empty. (#10169)

Fixes: #10154.
  • Loading branch information
blakeli0 committed Dec 19, 2023
1 parent 120f75d commit 081f276
Showing 1 changed file with 5 additions and 1 deletion.
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

0 comments on commit 081f276

Please sign in to comment.