簡體   English   中英

想要使用嵌入式憑據訪問Google Cloud Datastore

[英]Want to access Google Cloud Datastore with embedded credentials

我有一個Java應用程序,要在Google Cloud Datastore中存儲用戶數據。 入門教程中給出的步驟提到將憑據添加到環境中,但這對於最終用戶而言似乎不是一個好的解決方案。 我想做的是根據一組嵌入式憑據(文件或字符串集)生成與數據庫的連接。 這樣一來,我可以在用戶僅按常規使用應用程序的情況下管理憑據。

有沒有一種方法可以創建DatastoreService對象並手動傳遞其憑據,而不是使用.getCredentialsFromEnv()方法?

是的,您可以使用.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 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM