【问题标题】:How do you add KeyManager to a kms key mocked using moto如何将 KeyManager 添加到使用 moto 模拟的 kms 密钥
【发布时间】:2020-01-03 21:32:27
【问题描述】:

我想创建一个由 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 方法的行为?

key['KeyMetadata']['AWSAccountId'] 将返回模拟值,然后 key['KeyMetadata']['KeyManager'] 将返回另一个我可以指定的模拟值。

【问题讨论】:

    标签: python amazon-web-services boto3 moto


    【解决方案1】:

    KeyManager 属性是currently not returned by Moto,您可以在 Moto GitHub 上打开一个问题,也可以自己添加(本地或 PR'ed 到上游)

    【讨论】:

    • 啊....有关如何仅针对特定 KeyManager 字段模拟该字典中的特定返回值的任何建议?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-18
    • 1970-01-01
    • 2021-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多