如果您使用手動建立的 gRPC 程式庫呼叫 Cloud Key Management Service,必須在呼叫的中繼資料或標頭中指定 x-google-request-params
值。正確使用 x-google-request-params
會將呼叫轉送至 Cloud KMS 資源的適當地區。
請按下表所示,將 x-google-request-params
值設定為方法要求中的欄位。
設定要求欄位
下列範例說明在各種方法中指定資源名稱的位置。請將樣式設為 place-holder 的文字替換為在 Cloud KMS 資源 ID 中使用的實際值。
Decrypt 範例
如果您呼叫 Decrypt,必須在要求中填入下列欄位:
name: 'projects/project-id/locations/location/keyRings/key-ring/cryptoKeys/key-name/' ciphertext: 'iQALWM/r6alAxQm0VQe3...'
指派給 name
欄位的值是 CryptoKey 的資源名稱。如要正確轉送呼叫,您也必須將這個資源名稱包含在呼叫中繼資料中,格式如下:
x-goog-request-params: 'name=projects/project-id/locations/location/keyRings/key-ring/cryptoKeys/key-name/'
CreateKeyRing 範例
如果您呼叫 CreateKeyRing,必須在要求中填入下列欄位:
parent: 'projects/project-id/locations/location/' key_ring_id: 'myKeyRing' ...
呼叫中繼資料也必須包含 parent
資源名稱:
x-goog-request-params: 'parent=projects/project-id/locations/location/'
UpdateCryptoKey 範例
如果您呼叫 UpdateCryptoKey,必須在要求中填入下列欄位:
name: 'projects/project-id/locations/location/keyRings/key-ring/cryptoKeys/key-name/' field_mask: ...
中繼資料也必須包含 name
資源名稱。請注意,格式使用 crypto_key.name=
,而不是 name=
:
x-goog-request-params: 'crypto_key.name=projects/project-id/locations/location/keyRings/key-ring/cryptoKeys/key-name/'
使用 C++ 新增中繼資料
如果您使用 C++,請先呼叫 ClientContext::AddMetadata
再進行遠端程序呼叫 (RPC),以將適當資訊新增至呼叫中繼資料。
例如,如果您針對 Decrypt 的呼叫新增中繼資料:
context.AddMetadata("x-goog-request-params", "name=projects/project-id/locations/location/keyRings/key-ring-name/cryptoKeys/key-name/");
然後您可以照常將內容傳送至方法呼叫,以及要求與回應通訊協定緩衝區。