我有一個谷歌云功能,我可以使用gcloud具有必要 IAM 權限的服務帳戶使用cli呼叫
gcloud auth activate-service-account 'service-account-email' --key-file=google_key.json
gcloud functions call opt_manual --data '{some-json}'
這作業得很好。
我正在嘗試使用官方 ruby?? sdk https://github.com/googleapis/google-cloud-ruby/tree/main/google-cloud-functions-v1實作類似的呼叫
name = "opt_manual"
data = '{some-json}'
client = ::Google::Cloud::Functions::V1::CloudFunctionsService::Client.new do |config|
config.credentials = "google_key.json"
end
client.get_function ::Google::Cloud::Functions::V1::GetFunctionRequest.new(name: name)
# =>
# Permission denied on resource project opt_manual.. debug_error_string:{
# "created":"@1636730694.210272000",
# "description":"Error received from peer ipv4:142.251.36.202:443",
# "file":"src/core/lib/surface/call.cc",
# "file_line":1070,
# "grpc_message":"Permission denied on resource project opt_manual.",
# "grpc_status":7
# } (Google::Cloud::PermissionDeniedError)
服務帳戶包括以下權限:
- 云功能管理員
- 云函式呼叫程式
- 服務帳號用戶
- 作業負載身份用戶
云功能原則包括正確的服務帳號。
盡管如此,我仍然得到PermissionDeniedError也許有人有類似的情況,還記得如何修復嗎?請記住,在同一個專案中,我使用相同的服務帳戶使用官方 SDK 訪問 bigquery 和云存盤沒有任何問題。
uj5u.com熱心網友回復:
您可以用值替換以下內容并嘗試使用它而不是opt_manual:
projects/{project}/locations/{location}/functions/opt_manual
您的服務帳戶可能有太多權限。您應該只需要 Cloud Functions Invoker ( roles/cloudfunctions.invoker)。
解釋底層方法呼叫是projects.locations.functions.get。不幸的是,GetFunctionsRequest的 Ruby API 檔案沒有解釋這一點。APIs Explorer是了解 Google REST API 的權威工具。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/359995.html
