无法更新uscentral1中的加密密钥

2024-05-23 19:01:41 发布

您现在位置:Python中文网/ 问答频道 /正文

出于某种原因,我似乎无法更新us-central1区域中的键。我的IAM同时具有更新和列表角色,我使用以下代码:

import google.cloud.kms as kms

self.client = kms.KeyManagementServiceClient()
name = 'client-1'
key_path = self.client.crypto_key_path(config.PROJECT, config.KMS_LOCATION, config.KMS_RING, name)

update_mask = {'paths': ['rotation_period', 'next_rotation_time']}
self.client.update_crypto_key({
        'name': key_path,
        'rotation_period': {'seconds': 0},
        'next_rotation_time': {'seconds': 0}
    }, update_mask)

它给了我以下错误:

google.api_core.exceptions.NotFound: 404 The request concerns location 'us-central1' but was sent to location 'global'. Either Cloud KMS is not available in 'us-central1' or the request was misrouted.

奇怪的是,列表和get工作正常。我也看到了一个解决方案,他们改变了客户端的传输参数,但我似乎找不到正确的地址

提前谢谢


Tags: pathkeynameselfclientconfig列表google
1条回答
网友
1楼 · 发布于 2024-05-23 19:01:41

这是一个bug,我们正在https://github.com/googleapis/gapic-generator/issues/3066跟踪它

同时,该错误的原因是当第一个参数是dict时,UpdateCryptoKey无法正确计算区域。如果它是一个resources_pb2.CryptoKey,那么它可以正常工作。例如:

import google.cloud.kms as kms
from google.cloud.kms_v1.proto import resources_pb2

client = kms.KeyManagementServiceClient()

ck = resources_pb2.CryptoKey()
ck.name = 'projects/{proj}/locations/us-central1/keyRings/{kr}/cryptoKeys/{key}'
ck.next_rotation_time.GetCurrentTime()

update_mask = {'paths': ['next_rotation_time']}
client.update_crypto_key(ck, update_mask)

希望这能让你在解决这个问题的同时解决这个问题。对给您带来的不便表示歉意,并感谢您的耐心等待

相关问题 更多 >