Add CreateTime property to EC2 key pair response (#6341)
This commit is contained in:
parent
18b6bdf20a
commit
b7624e10b1
@ -1,4 +1,5 @@
|
|||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from moto.core import BaseModel
|
from moto.core import BaseModel
|
||||||
from ..exceptions import (
|
from ..exceptions import (
|
||||||
@ -14,6 +15,7 @@ from ..utils import (
|
|||||||
generic_filter,
|
generic_filter,
|
||||||
random_key_pair_id,
|
random_key_pair_id,
|
||||||
)
|
)
|
||||||
|
from moto.core.utils import iso_8601_datetime_with_milliseconds
|
||||||
|
|
||||||
|
|
||||||
class KeyPair(BaseModel):
|
class KeyPair(BaseModel):
|
||||||
@ -22,6 +24,11 @@ class KeyPair(BaseModel):
|
|||||||
self.name = name
|
self.name = name
|
||||||
self.fingerprint = fingerprint
|
self.fingerprint = fingerprint
|
||||||
self.material = material
|
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:
|
def get_filter_value(self, filter_name: str) -> str:
|
||||||
if filter_name == "key-name":
|
if filter_name == "key-name":
|
||||||
|
@ -37,6 +37,7 @@ DESCRIBE_KEY_PAIRS_RESPONSE = """<DescribeKeyPairsResponse xmlns="http://ec2.ama
|
|||||||
<keySet>
|
<keySet>
|
||||||
{% for keypair in keypairs %}
|
{% for keypair in keypairs %}
|
||||||
<item>
|
<item>
|
||||||
|
<createTime>{{ keypair.created_iso_8601 }}</createTime>
|
||||||
<keyPairId>{{ keypair.id }}</keyPairId>
|
<keyPairId>{{ keypair.id }}</keyPairId>
|
||||||
<keyName>{{ keypair.name }}</keyName>
|
<keyName>{{ keypair.name }}</keyName>
|
||||||
<keyFingerprint>{{ keypair.fingerprint }}</keyFingerprint>
|
<keyFingerprint>{{ keypair.fingerprint }}</keyFingerprint>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
import sure # noqa # pylint: disable=unused-import
|
import sure # noqa # pylint: disable=unused-import
|
||||||
import boto3
|
import boto3
|
||||||
@ -101,6 +102,7 @@ def test_key_pairs_create_boto3():
|
|||||||
kps[0].should.have.key("KeyPairId")
|
kps[0].should.have.key("KeyPairId")
|
||||||
kps[0].should.have.key("KeyName").equal(key_name)
|
kps[0].should.have.key("KeyName").equal(key_name)
|
||||||
kps[0].should.have.key("KeyFingerprint")
|
kps[0].should.have.key("KeyFingerprint")
|
||||||
|
kps[0].should.have.key("CreateTime").should.be.a(datetime)
|
||||||
|
|
||||||
|
|
||||||
@mock_ec2
|
@mock_ec2
|
||||||
|
Loading…
Reference in New Issue
Block a user