summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Freudberg <jeremyfreudberg@gmail.com>2017-09-11 19:47:09 +0000
committerJeremy Freudberg <jeremyfreudberg@gmail.com>2017-09-11 19:47:09 +0000
commitb23bf3cefa1cfb93aca487f7b3ab281c78319c68 (patch)
tree6ee9a76e3d0d21cdaa4f9c27be25818b1fbc4b67
parentdfd5fff51db628817d09e59f8eb24d8065eb3505 (diff)
More attributes of flask.request in RequestDetails
To simplify the writing of extensions, and to reduce reliance on importing the flask.request global object, store pertinent attributes of flask.request in the RequestDetails class. Change-Id: Idff737155a6110d0520a74e36a5b0c23b5b5d93c
Notes
Notes (review): Code-Review+2: Kristi Nikolla <knikolla@bu.edu> Workflow+1: Kristi Nikolla <knikolla@bu.edu> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Wed, 13 Sep 2017 22:49:28 +0000 Reviewed-on: https://review.openstack.org/502554 Project: openstack/mixmatch Branch: refs/heads/master
-rw-r--r--mixmatch/extend/name_routing.py3
-rw-r--r--mixmatch/proxy.py13
2 files changed, 9 insertions, 7 deletions
diff --git a/mixmatch/extend/name_routing.py b/mixmatch/extend/name_routing.py
index 67f11de..f35a681 100644
--- a/mixmatch/extend/name_routing.py
+++ b/mixmatch/extend/name_routing.py
@@ -13,7 +13,6 @@
13# under the License. 13# under the License.
14 14
15from mixmatch.extend import base 15from mixmatch.extend import base
16from mixmatch.session import request as mm_request
17 16
18from oslo_serialization import jsonutils 17from oslo_serialization import jsonutils
19 18
@@ -35,7 +34,7 @@ class NameRouting(base.Extension):
35 if self._is_targeted(request.headers): 34 if self._is_targeted(request.headers):
36 return 35 return
37 36
38 body = jsonutils.loads(mm_request.data) 37 body = jsonutils.loads(request.body)
39 if request.service == 'image': 38 if request.service == 'image':
40 if request.version == 'v1': 39 if request.version == 'v1':
41 name = request.headers.get('X-IMAGE-META-NAME', '') 40 name = request.headers.get('X-IMAGE-META-NAME', '')
diff --git a/mixmatch/proxy.py b/mixmatch/proxy.py
index 446ddd1..0cec502 100644
--- a/mixmatch/proxy.py
+++ b/mixmatch/proxy.py
@@ -94,6 +94,10 @@ class RequestDetails(object):
94 self.token = headers.get('X-AUTH-TOKEN', None) 94 self.token = headers.get('X-AUTH-TOKEN', None)
95 self.headers = dict(headers) 95 self.headers = dict(headers)
96 self.path = orig_path 96 self.path = orig_path
97 self.args = dict(request.args)
98 # NOTE(jfreud): if chunked transfer, body must be accessed through
99 # utilities found in mixmatch.session
100 self.body = request.data
97 101
98 102
99class RequestHandler(object): 103class RequestHandler(object):
@@ -187,13 +191,13 @@ class RequestHandler(object):
187 'method': self.details.method, 191 'method': self.details.method,
188 'url': url, 192 'url': url,
189 'headers': headers, 193 'headers': headers,
190 'params': self._prepare_args(request.args) 194 'params': self._prepare_args(self.details.args)
191 } 195 }
192 if self.chunked: 196 if self.chunked:
193 resp = self.session.request(data=chunked_reader(), 197 resp = self.session.request(data=chunked_reader(),
194 **request_kwargs) 198 **request_kwargs)
195 else: 199 else:
196 resp = self.session.request(data=request.data, 200 resp = self.session.request(data=self.details.body,
197 stream=self.stream, 201 stream=self.stream,
198 **request_kwargs) 202 **request_kwargs)
199 LOG.info(format_for_log(title='Request from proxy', 203 LOG.info(format_for_log(title='Request from proxy',
@@ -265,7 +269,7 @@ class RequestHandler(object):
265 self.details.action[0], 269 self.details.action[0],
266 self.details.service, 270 self.details.service,
267 version=self.details.version, 271 version=self.details.version,
268 params=dict(request.args), 272 params=self.details.args,
269 path=request.base_url, 273 path=request.base_url,
270 strip_details=self.strip_details), 274 strip_details=self.strip_details),
271 200, 275 200,
@@ -304,13 +308,12 @@ class RequestHandler(object):
304 return headers 308 return headers
305 309
306 @staticmethod 310 @staticmethod
307 def _prepare_args(user_args): 311 def _prepare_args(args):
308 """Prepare the GET arguments by removing the limit and marker. 312 """Prepare the GET arguments by removing the limit and marker.
309 313
310 This is because the id of the marker will only be present in one of 314 This is because the id of the marker will only be present in one of
311 the service providers. 315 the service providers.
312 """ 316 """
313 args = dict(user_args)
314 if CONF.aggregation: 317 if CONF.aggregation:
315 args.pop('limit', None) 318 args.pop('limit', None)
316 args.pop('marker', None) 319 args.pop('marker', None)