Properly dispatch by api version in server mode
I'm not happy with this solution. Please think of a fix if you're reading this.
This commit is contained in:
parent
5cd1e2450d
commit
ce392fab79
3 changed files with 49 additions and 25 deletions
|
|
@ -1,10 +1,38 @@
|
|||
from __future__ import unicode_literals
|
||||
from .responses import ELBResponse
|
||||
from moto.elbv2.responses import ELBV2Response
|
||||
|
||||
|
||||
def api_version_elb_backend(*args, **kwargs):
|
||||
"""
|
||||
ELB and ELBV2 (Classic and Application load balancers) use the same
|
||||
hostname and url space. To differentiate them we must read the
|
||||
`Version` parameter out of the url-encoded request body. TODO: There
|
||||
has _got_ to be a better way to do this. Please help us think of
|
||||
one.
|
||||
"""
|
||||
request = args[0]
|
||||
|
||||
if hasattr(request, 'values'):
|
||||
# boto3
|
||||
version = request.values.get('Version')
|
||||
else:
|
||||
# boto
|
||||
request.parse_request()
|
||||
version = request.querystring.get('Version')[0]
|
||||
|
||||
if '2012-06-01' == version:
|
||||
return ELBResponse.dispatch(*args, **kwargs)
|
||||
elif '2015-12-01' == version:
|
||||
return ELBV2Response.dispatch(*args, **kwargs)
|
||||
else:
|
||||
raise Exception("Unknown ELB API version: {}".format(version))
|
||||
|
||||
|
||||
url_bases = [
|
||||
"https?://elasticloadbalancing.(.+).amazonaws.com",
|
||||
]
|
||||
|
||||
url_paths = {
|
||||
'{0}/$': ELBResponse.dispatch,
|
||||
'{0}/$': api_version_elb_backend,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue