Question

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?

Was it helpful?

Solution

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) {
    ...
  }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top