googleapis / google-auth-library-java

Open source Auth client library for Java
https://developers.google.com/identity
BSD 3-Clause "New" or "Revised" License
405 stars 218 forks source link

Previously, I use google-cloud-vertexai 0.3. I can't use service account json in 1.3. #1406

Closed SetoKaiba closed 1 month ago

SetoKaiba commented 1 month ago

Thanks for stopping by to let us know something could be better!

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

Please run down the following list and make sure you've tried the usual "quick fixes":

If you are still having issues, please include as much information as possible:

Environment details

  1. google-cloud-vertexai
  2. OS type and version: Not related
  3. Java version: Not related
  4. version(s): 1.3.0

Steps to reproduce

  1. Check the code example.
  2. Previously, I can pass the Credentials to the VertexAI constructor.
  3. Now, I can't.
  4. Service account is more convenient for deployment instead of ADC.
  5. How can I use service account json in the new version?

Code example

    private GoogleCredentials getGoogleCredentials() {
        if (googleCredentials == null) {
            try {
                List<String> defaultScopes =
                        PredictionServiceStubSettings.defaultCredentialsProviderBuilder().getScopesToApply();
                googleCredentials = GoogleCredentials.fromStream(new FileInputStream(serviceAccountFile)).createScoped(defaultScopes);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return googleCredentials;
    }

    private VertexAI getVertexAI() {
        if (vertexAI == null) {
            vertexAI = new VertexAI(projectId, location, getGoogleCredentials());
        }
        return vertexAI;
    }

Stack trace

Any relevant stacktrace here.

External references such as API reference guides

Any additional information below

Following these steps guarantees the quickest resolution possible.

Thanks!

SetoKaiba commented 1 month ago

OK. I see. Use builder instead.