Merge pull request #2639 from corrjo/instance_connect

Resolves #2637  added send_ssh_public_key
This commit is contained in:
Mike Grima 2019-12-27 08:51:27 -08:00 committed by GitHub
commit 664e959856
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 58 additions and 2 deletions

View File

@ -2694,7 +2694,7 @@
## ec2-instance-connect
0% implemented
- [ ] send_ssh_public_key
- [x] send_ssh_public_key
## ecr
27% implemented

View File

@ -21,6 +21,7 @@ from .dynamodb import mock_dynamodb, mock_dynamodb_deprecated # noqa
from .dynamodb2 import mock_dynamodb2, mock_dynamodb2_deprecated # noqa
from .dynamodbstreams import mock_dynamodbstreams # noqa
from .ec2 import mock_ec2, mock_ec2_deprecated # noqa
from .ec2_instance_connect import mock_ec2_instance_connect # noqa
from .ecr import mock_ecr, mock_ecr_deprecated # noqa
from .ecs import mock_ecs, mock_ecs_deprecated # noqa
from .elb import mock_elb, mock_elb_deprecated # noqa

View File

@ -19,6 +19,7 @@ from moto.dynamodb import dynamodb_backends
from moto.dynamodb2 import dynamodb_backends2
from moto.dynamodbstreams import dynamodbstreams_backends
from moto.ec2 import ec2_backends
from moto.ec2_instance_connect import ec2_instance_connect_backends
from moto.ecr import ecr_backends
from moto.ecs import ecs_backends
from moto.elb import elb_backends
@ -71,6 +72,7 @@ BACKENDS = {
"dynamodb2": dynamodb_backends2,
"dynamodbstreams": dynamodbstreams_backends,
"ec2": ec2_backends,
"ec2_instance_connect": ec2_instance_connect_backends,
"ecr": ecr_backends,
"ecs": ecs_backends,
"elb": elb_backends,

View File

@ -2,6 +2,6 @@ from __future__ import unicode_literals
from .responses import EC2Response
url_bases = ["https?://ec2.(.+).amazonaws.com(|.cn)"]
url_bases = ["https?://ec2\.(.+)\.amazonaws\.com(|\.cn)"]
url_paths = {"{0}/": EC2Response.dispatch}

View File

@ -0,0 +1,4 @@
from ..core.models import base_decorator
from .models import ec2_instance_connect_backends
mock_ec2_instance_connect = base_decorator(ec2_instance_connect_backends)

View File

@ -0,0 +1,11 @@
import boto
from moto.core import BaseBackend
class Ec2InstanceConnectBackend(BaseBackend):
pass
ec2_instance_connect_backends = {}
for region in boto.ec2.regions():
ec2_instance_connect_backends[region.name] = Ec2InstanceConnectBackend()

View File

@ -0,0 +1,9 @@
import json
from moto.core.responses import BaseResponse
class Ec2InstanceConnectResponse(BaseResponse):
def send_ssh_public_key(self):
return json.dumps(
{"RequestId": "example-2a47-4c91-9700-e37e85162cb6", "Success": True}
)

View File

@ -0,0 +1,6 @@
from __future__ import unicode_literals
from .responses import Ec2InstanceConnectResponse
url_bases = ["https?://ec2-instance-connect\.(.+)\.amazonaws\.com"]
url_paths = {"{0}/$": Ec2InstanceConnectResponse.dispatch}

View File

@ -0,0 +1,23 @@
import boto3
from moto import mock_ec2_instance_connect
pubkey = """ssh-rsa
AAAAB3NzaC1yc2EAAAADAQABAAABAQDV5+voluw2zmzqpqCAqtsyoP01TQ8Ydx1eS1yD6wUsHcPqMIqpo57YxiC8XPwrdeKQ6GG6MC3bHsgXoPypGP0LyixbiuLTU31DnnqorcHt4bWs6rQa7dK2pCCflz2fhYRt5ZjqSNsAKivIbqkH66JozN0SySIka3kEV79GdB0BicioKeEJlCwM9vvxafyzjWf/z8E0lh4ni3vkLpIVJ0t5l+Qd9QMJrT6Is0SCQPVagTYZoi8+fWDoGsBa8vyRwDjEzBl28ZplKh9tSyDkRIYszWTpmK8qHiqjLYZBfAxXjGJbEYL1iig4ZxvbYzKEiKSBi1ZMW9iWjHfZDZuxXAmB
example
"""
@mock_ec2_instance_connect
def test_send_ssh_public_key():
client = boto3.client("ec2-instance-connect", region_name="us-east-1")
fake_request_id = "example-2a47-4c91-9700-e37e85162cb6"
response = client.send_ssh_public_key(
InstanceId="i-abcdefg12345",
InstanceOSUser="ec2-user",
SSHPublicKey=pubkey,
AvailabilityZone="us-east-1a",
)
assert response["RequestId"] == fake_request_id