ec2: add support for creation and importing of real SSH keys (#2108)
* ec2: add support for creation and importing of real SSH keys * setup: lock PyYAML version to avoid incompatibilities
This commit is contained in:
parent
d8ff67197b
commit
fb2a76fd66
8 changed files with 179 additions and 37 deletions
|
|
@ -20,6 +20,7 @@ from boto.ec2.blockdevicemapping import BlockDeviceMapping, BlockDeviceType
|
|||
from boto.ec2.spotinstancerequest import SpotInstanceRequest as BotoSpotRequest
|
||||
from boto.ec2.launchspecification import LaunchSpecification
|
||||
|
||||
|
||||
from moto.compat import OrderedDict
|
||||
from moto.core import BaseBackend
|
||||
from moto.core.models import Model, BaseModel
|
||||
|
|
@ -43,6 +44,7 @@ from .exceptions import (
|
|||
InvalidInstanceIdError,
|
||||
InvalidInternetGatewayIdError,
|
||||
InvalidKeyPairDuplicateError,
|
||||
InvalidKeyPairFormatError,
|
||||
InvalidKeyPairNameError,
|
||||
InvalidNetworkAclIdError,
|
||||
InvalidNetworkAttachmentIdError,
|
||||
|
|
@ -120,6 +122,8 @@ from .utils import (
|
|||
random_customer_gateway_id,
|
||||
is_tag_filter,
|
||||
tag_filter_matches,
|
||||
rsa_public_key_parse,
|
||||
rsa_public_key_fingerprint
|
||||
)
|
||||
|
||||
INSTANCE_TYPES = json.load(
|
||||
|
|
@ -910,7 +914,14 @@ class KeyPairBackend(object):
|
|||
def import_key_pair(self, key_name, public_key_material):
|
||||
if key_name in self.keypairs:
|
||||
raise InvalidKeyPairDuplicateError(key_name)
|
||||
keypair = KeyPair(key_name, **random_key_pair())
|
||||
|
||||
try:
|
||||
rsa_public_key = rsa_public_key_parse(public_key_material)
|
||||
except ValueError:
|
||||
raise InvalidKeyPairFormatError()
|
||||
|
||||
fingerprint = rsa_public_key_fingerprint(rsa_public_key)
|
||||
keypair = KeyPair(key_name, material=public_key_material, fingerprint=fingerprint)
|
||||
self.keypairs[key_name] = keypair
|
||||
return keypair
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue