简体   繁体   中英

Want to access Google Cloud Datastore with embedded credentials

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) {
    ...
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM