Add CreateTime property to EC2 key pair response (#6341)

This commit is contained in:
Alex Chesters 2023-05-25 21:55:41 +01:00 committed by GitHub
parent 18b6bdf20a
commit b7624e10b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 0 deletions

View File

@ -1,4 +1,5 @@
from typing import Any, Dict, List
from datetime import datetime
from moto.core import BaseModel
from ..exceptions import (
@ -14,6 +15,7 @@ from ..utils import (
generic_filter,
random_key_pair_id,
)
from moto.core.utils import iso_8601_datetime_with_milliseconds
class KeyPair(BaseModel):
@ -22,6 +24,11 @@ class KeyPair(BaseModel):
self.name = name
self.fingerprint = fingerprint
self.material = material
self.create_time = datetime.utcnow()
@property
def created_iso_8601(self) -> str:
return iso_8601_datetime_with_milliseconds(self.create_time)
def get_filter_value(self, filter_name: str) -> str:
if filter_name == "key-name":

View File

@ -37,6 +37,7 @@ DESCRIBE_KEY_PAIRS_RESPONSE = """<DescribeKeyPairsResponse xmlns="http://ec2.ama
<keySet>
{% for keypair in keypairs %}
<item>
<createTime>{{ keypair.created_iso_8601 }}</createTime>
<keyPairId>{{ keypair.id }}</keyPairId>
<keyName>{{ keypair.name }}</keyName>
<keyFingerprint>{{ keypair.fingerprint }}</keyFingerprint>

View File

@ -1,4 +1,5 @@
import pytest
from datetime import datetime
import sure # noqa # pylint: disable=unused-import
import boto3
@ -101,6 +102,7 @@ def test_key_pairs_create_boto3():
kps[0].should.have.key("KeyPairId")
kps[0].should.have.key("KeyName").equal(key_name)
kps[0].should.have.key("KeyFingerprint")
kps[0].should.have.key("CreateTime").should.be.a(datetime)
@mock_ec2