Get standalone server mode working for all tests.
This commit is contained in:
parent
cb28eeefbb
commit
81836b6981
78 changed files with 957 additions and 783 deletions
4
moto/instance_metadata/__init__.py
Normal file
4
moto/instance_metadata/__init__.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
from __future__ import unicode_literals
|
||||
from .models import instance_metadata_backend
|
||||
|
||||
instance_metadata_backends = {"global": instance_metadata_backend}
|
||||
7
moto/instance_metadata/models.py
Normal file
7
moto/instance_metadata/models.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
from moto.core.models import BaseBackend
|
||||
|
||||
|
||||
class InstanceMetadataBackend(BaseBackend):
|
||||
pass
|
||||
|
||||
instance_metadata_backend = InstanceMetadataBackend()
|
||||
47
moto/instance_metadata/responses.py
Normal file
47
moto/instance_metadata/responses.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
from __future__ import unicode_literals
|
||||
import datetime
|
||||
import json
|
||||
from urlparse import urlparse
|
||||
|
||||
from moto.core.responses import BaseResponse
|
||||
|
||||
|
||||
class InstanceMetadataResponse(BaseResponse):
|
||||
def metadata_response(self, request, full_url, headers):
|
||||
"""
|
||||
Mock response for localhost metadata
|
||||
|
||||
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html
|
||||
"""
|
||||
|
||||
parsed_url = urlparse(full_url)
|
||||
tomorrow = datetime.datetime.utcnow() + datetime.timedelta(days=1)
|
||||
credentials = dict(
|
||||
AccessKeyId="test-key",
|
||||
SecretAccessKey="test-secret-key",
|
||||
Token="test-session-token",
|
||||
Expiration=tomorrow.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
)
|
||||
|
||||
path = parsed_url.path
|
||||
|
||||
meta_data_prefix = "/latest/meta-data/"
|
||||
# Strip prefix if it is there
|
||||
if path.startswith(meta_data_prefix):
|
||||
path = path[len(meta_data_prefix):]
|
||||
|
||||
if path == '':
|
||||
result = 'iam'
|
||||
elif path == 'iam':
|
||||
result = json.dumps({
|
||||
'security-credentials': {
|
||||
'default-role': credentials
|
||||
}
|
||||
})
|
||||
elif path == 'iam/security-credentials/':
|
||||
result = 'default-role'
|
||||
elif path == 'iam/security-credentials/default-role':
|
||||
result = json.dumps(credentials)
|
||||
else:
|
||||
raise NotImplementedError("The {0} metadata path has not been implemented".format(path))
|
||||
return 200, headers, result
|
||||
12
moto/instance_metadata/urls.py
Normal file
12
moto/instance_metadata/urls.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
from __future__ import unicode_literals
|
||||
from .responses import InstanceMetadataResponse
|
||||
|
||||
url_bases = [
|
||||
"http://169.254.169.254"
|
||||
]
|
||||
|
||||
instance_metadata = InstanceMetadataResponse()
|
||||
|
||||
url_paths = {
|
||||
'{0}/(?P<path>.+)': instance_metadata.metadata_response,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue