Store Region-info in UserAgent-header
This commit is contained in:
parent
c5f8fa4e1f
commit
7d43a1d23d
@ -10,6 +10,7 @@ import six
|
|||||||
import types
|
import types
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from botocore.config import Config
|
||||||
from botocore.handlers import BUILTIN_HANDLERS
|
from botocore.handlers import BUILTIN_HANDLERS
|
||||||
from botocore.awsrequest import AWSResponse
|
from botocore.awsrequest import AWSResponse
|
||||||
from six.moves.urllib.parse import urlparse
|
from six.moves.urllib.parse import urlparse
|
||||||
@ -416,6 +417,8 @@ class ServerModeMockAWS(BaseMockAWS):
|
|||||||
import mock
|
import mock
|
||||||
|
|
||||||
def fake_boto3_client(*args, **kwargs):
|
def fake_boto3_client(*args, **kwargs):
|
||||||
|
service, region = args
|
||||||
|
kwargs["config"] = Config(user_agent_extra="region/"+region)
|
||||||
if "endpoint_url" not in kwargs:
|
if "endpoint_url" not in kwargs:
|
||||||
kwargs["endpoint_url"] = "http://localhost:5000"
|
kwargs["endpoint_url"] = "http://localhost:5000"
|
||||||
return real_boto3_client(*args, **kwargs)
|
return real_boto3_client(*args, **kwargs)
|
||||||
|
@ -188,6 +188,7 @@ class BaseResponse(_TemplateEnvironmentMixin, ActionAuthenticatorMixin):
|
|||||||
default_region = "us-east-1"
|
default_region = "us-east-1"
|
||||||
# to extract region, use [^.]
|
# to extract region, use [^.]
|
||||||
region_regex = re.compile(r"\.(?P<region>[a-z]{2}-[a-z]+-\d{1})\.amazonaws\.com")
|
region_regex = re.compile(r"\.(?P<region>[a-z]{2}-[a-z]+-\d{1})\.amazonaws\.com")
|
||||||
|
region_from_useragent_regex = re.compile(r"region/(?P<region>[a-z]{2}-[a-z]+-\d{1})")
|
||||||
param_list_regex = re.compile(r"(.*)\.(\d+)\.")
|
param_list_regex = re.compile(r"(.*)\.(\d+)\.")
|
||||||
access_key_regex = re.compile(
|
access_key_regex = re.compile(
|
||||||
r"AWS.*(?P<access_key>(?<![A-Z0-9])[A-Z0-9]{20}(?![A-Z0-9]))[:/]"
|
r"AWS.*(?P<access_key>(?<![A-Z0-9])[A-Z0-9]{20}(?![A-Z0-9]))[:/]"
|
||||||
@ -272,9 +273,12 @@ class BaseResponse(_TemplateEnvironmentMixin, ActionAuthenticatorMixin):
|
|||||||
self.response_headers = {"server": "amazon.com"}
|
self.response_headers = {"server": "amazon.com"}
|
||||||
|
|
||||||
def get_region_from_url(self, request, full_url):
|
def get_region_from_url(self, request, full_url):
|
||||||
match = self.region_regex.search(full_url)
|
url_match = self.region_regex.search(full_url)
|
||||||
if match:
|
user_agent_match = self.region_from_useragent_regex.search(request.headers["User-Agent"])
|
||||||
region = match.group(1)
|
if url_match:
|
||||||
|
region = url_match.group(1)
|
||||||
|
elif user_agent_match:
|
||||||
|
region = user_agent_match.group(1)
|
||||||
elif (
|
elif (
|
||||||
"Authorization" in request.headers
|
"Authorization" in request.headers
|
||||||
and "AWS4" in request.headers["Authorization"]
|
and "AWS4" in request.headers["Authorization"]
|
||||||
|
Loading…
Reference in New Issue
Block a user