python - 如何将 KeyManager 添加到使用 moto 模拟的 kms 密钥中
问题描述
我想创建一个由 AWS 管理的密钥。到目前为止,这就是我所拥有的
@mock_kms
def test_mocking_getting_keys(self):
session = boto3.Session(profile_name=profile)
client = session.client('kms', 'us-east-2')
key = client.create_key(
Policy='string',
Description='string',
KeyUsage='SIGN_VERIFY',
CustomerMasterKeySpec='RSA_2048',
Origin='AWS_KMS',
CustomKeyStoreId='string',
BypassPolicyLockoutSafetyCheck=True,
Tags=[
{
'TagKey': 'string',
'TagValue': 'string'
},
]
)
print(key)
但密钥似乎没有 KeyManager 字段:
{'KeyMetadata': {'AWSAccountId': '012345678912', 'KeyId': '7fc3e676-0d1c-4526-9161-41b27a776033', 'Arn': 'arn:aws:kms:us-east-2:012345678912:key/7fc3e676-0d1c-4526-9161-41b27a776033', 'CreationDate': datetime.datetime(2020, 1, 3, 13, 31, 17, tzinfo=tzutc()), 'Enabled': True, 'Description': 'string', 'KeyUsage': 'SIGN_VERIFY', 'KeyState': 'Enabled'}, 'ResponseMetadata': {'HTTPStatusCode': 200, 'HTTPHeaders': {'server': 'amazon.com'}, 'RetryAttempts': 0}}
我尝试在 create_key 调用期间将 KeyManager 添加为参数,但这也不起作用。
好像 moto 不返回 KeyManager 字段。有没有办法专门模拟该返回值但不改变其余参数的 dictionary.get 方法的行为?
IE
key['KeyMetadata']['AWSAccountId']
将返回模拟值,然后
key['KeyMetadata']['KeyManager']
返回另一个我可以指定的模拟值。
解决方案
Moto 当前不返回该KeyManager
属性,您可以在 Moto GitHub 上打开一个问题,或者自己添加它(本地或 PR'ed 到上游)
推荐阅读
- types - 为什么向 HashMap 中插入值总是导致值为 None?
- java - 通过调用其对象名称从数组中删除和对象
- javascript - decodeURIComponent() 抛出格式错误的 URI 序列
- python - pymongo 查询现有集合
- excel - 将列从一张工作表复制到新工作表
- bash - BubbleSort Bash 没有排序
- typescript - 禁止生产构建的控制台输出
- java - 如何在 JButtom 后面制作 fillPolygon(s)
- ionic-framework - 检查我的 ionic 应用程序在 AppStore 和 PlayStore 上是否有新版本
- amazon-web-services - AWS 登录 Web 应用程序的方式