문제

I have a Java Application that I want to store User Data for in Google Cloud Datastore. The steps given in the Getting Started tutorial mention adding the credentials to the Environment, but that doesn't seem like a good solution for end users. What I would like to be able to do is generate a connection to the database from a set of embedded credentials (a file or set of strings). That way I could manage the credentials under the hood while the user just keeps using the application as normal.

Is there a way to create a DatastoreService object and pass it credentials manually instead of using the .getCredentialsFromEnv() method?

도움이 되었습니까?

해결책

Yes, you could use .getServiceAccountCredential

  /**
   * Constructs credentials for the given account and key.
   *
   * @param account the account to use.
   * @param privateKeyFile the file name from which to get the private key.
   * @return valid credentials or {@code null}
   */
  public static Credential getServiceAccountCredential(String account, String privateKeyFile) {
    ...
  }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top