Skip to content

Commit 12f9a3c

Browse files
fix: [vertexai] deprecate varargs scopes in VertexAI (#10328)
PiperOrigin-RevId: 604674686 Co-authored-by: Jaycee Li <jayceeli@google.com>
1 parent a5cc91a commit 12f9a3c

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

java-vertexai/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -505,4 +505,4 @@ Java is a registered trademark of Oracle and/or its affiliates.
505505
[apilibs]: https://cloud.google.com/apis/docs/client-libraries-explained#google_api_client_libraries
506506
[oracle]: https://www.oracle.com/java/technologies/java-se-support-roadmap.html
507507
[g-c-j]: http://github.com/googleapis/google-cloud-java
508-
[generative-ai-studio]: https://cloud.google.com/generative-ai-studio?hl=en
508+
[generative-ai-studio]: https://cloud.google.com/generative-ai-studio?hl=en

java-vertexai/google-cloud-vertexai/src/main/java/com/google/cloud/vertexai/VertexAI.java

+66-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.google.cloud.vertexai.api.PredictionServiceSettings;
3030
import java.io.IOException;
3131
import java.util.Arrays;
32+
import java.util.List;
3233
import java.util.logging.Level;
3334
import java.util.logging.Logger;
3435

@@ -60,16 +61,38 @@ public class VertexAI implements AutoCloseable {
6061
private LlmUtilityServiceClient llmUtilityRestClient = null;
6162

6263
/**
63-
* Construct a VertexAI instance with custom credentials.
64+
* Construct a VertexAI instance.
6465
*
6566
* @param projectId the default project to use when making API calls
6667
* @param location the default location to use when making API calls
67-
* @param credentials the custom credentials to use when making API calls
6868
*/
69-
public VertexAI(String projectId, String location, Credentials credentials) {
69+
public VertexAI(String projectId, String location) {
7070
this.projectId = projectId;
7171
this.location = location;
7272
this.apiEndpoint = String.format("%s-aiplatform.googleapis.com", this.location);
73+
}
74+
75+
/**
76+
* Construct a VertexAI instance with default transport layer.
77+
*
78+
* @param projectId the default project to use when making API calls
79+
* @param location the default location to use when making API calls
80+
* @param transport the default {@link Transport} layer to use to send API requests
81+
*/
82+
public VertexAI(String projectId, String location, Transport transport) {
83+
this(projectId, location);
84+
this.transport = transport;
85+
}
86+
87+
/**
88+
* Construct a VertexAI instance with custom credentials.
89+
*
90+
* @param projectId the default project to use when making API calls
91+
* @param location the default location to use when making API calls
92+
* @param credentials the custom credentials to use when making API calls
93+
*/
94+
public VertexAI(String projectId, String location, Credentials credentials) {
95+
this(projectId, location);
7396
this.credentialsProvider = FixedCredentialsProvider.create(credentials);
7497
}
7598

@@ -91,9 +114,47 @@ public VertexAI(String projectId, String location, Transport transport, Credenti
91114
*
92115
* @param projectId the default project to use when making API calls
93116
* @param location the default location to use when making API calls
117+
* @param scopes List of scopes in the default credentials. Make sure you have specified
118+
* "https://www.googleapis.com/auth/cloud-platform" scope to access resources on Vertex AI.
119+
*/
120+
public VertexAI(String projectId, String location, List<String> scopes) throws IOException {
121+
this(projectId, location);
122+
123+
CredentialsProvider credentialsProvider =
124+
scopes.size() == 0
125+
? null
126+
: GoogleCredentialsProvider.newBuilder()
127+
.setScopesToApply(scopes)
128+
.setUseJwtAccessWithScope(true)
129+
.build();
130+
this.credentialsProvider = credentialsProvider;
131+
}
132+
133+
/**
134+
* Construct a VertexAI instance with default transport layer and application default credentials.
135+
*
136+
* @param projectId the default project to use when making API calls
137+
* @param location the default location to use when making API calls
138+
* @param transport the default {@link Transport} layer to use to send API requests
139+
* @param scopes List of scopes in the default credentials. Make sure you have specified
140+
* "https://www.googleapis.com/auth/cloud-platform" scope to access resources on Vertex AI.
141+
*/
142+
public VertexAI(String projectId, String location, Transport transport, List<String> scopes)
143+
throws IOException {
144+
this(projectId, location, scopes);
145+
this.transport = transport;
146+
}
147+
148+
/**
149+
* Construct a VertexAI instance with application default credentials.
150+
*
151+
* @deprecated Use {@link #VertexAI(String, String, List<String>)} instead.
152+
* @param projectId the default project to use when making API calls
153+
* @param location the default location to use when making API calls
94154
* @param scopes collection of scopes in the default credentials. Make sure you have specified
95155
* "https://www.googleapis.com/auth/cloud-platform" scope to access resources on Vertex AI.
96156
*/
157+
@Deprecated
97158
public VertexAI(String projectId, String location, String... scopes) throws IOException {
98159
CredentialsProvider credentialsProvider =
99160
scopes.length == 0
@@ -112,11 +173,13 @@ public VertexAI(String projectId, String location, String... scopes) throws IOEx
112173
/**
113174
* Construct a VertexAI instance with default transport layer and application default credentials.
114175
*
176+
* @deprecated Use {@link #VertexAI(String, String, Transport, List<String>)} instead.
115177
* @param projectId the default project to use when making API calls
116178
* @param location the default location to use when making API calls
117179
* @param transport the default {@link Transport} layer to use to send API requests
118180
* @param scopes collection of scopes in the default credentials
119181
*/
182+
@Deprecated
120183
public VertexAI(String projectId, String location, Transport transport, String... scopes)
121184
throws IOException {
122185
this(projectId, location, scopes);

0 commit comments

Comments
 (0)