summaryrefslogtreecommitdiff
path: root/keystoneclient/client.py
diff options
context:
space:
mode:
authorIonuț Arțăriși <iartarisi@suse.cz>2012-09-13 15:45:40 +0200
committerIonuț Arțăriși <iartarisi@suse.cz>2012-10-22 17:47:26 +0200
commit56a4e4bd7da1353684d34e5a9817b88501e41d8c (patch)
tree8e974d319118ba8f738288410d0960370ecea4e3 /keystoneclient/client.py
parente04b0e16ae4ef3c63cedf05979cca93595f34f28 (diff)
downloadpython-keystoneclient-56a4e4bd7da1353684d34e5a9817b88501e41d8c.tar.gz
add a new HTTPClient attr for setting the original IP
The original IP is useful in cases where keystoneclient is used by a different openstack component and we need to know who made the original request. Otherwise it gets overwritten by e.g. Dashboard's host's IP. bug 1046837 Change-Id: Ic22c565e92010afd89c8573c375919215b70d73d
Diffstat (limited to 'keystoneclient/client.py')
-rw-r--r--keystoneclient/client.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/keystoneclient/client.py b/keystoneclient/client.py
index d862136..c61f891 100644
--- a/keystoneclient/client.py
+++ b/keystoneclient/client.py
@@ -39,7 +39,7 @@ class HTTPClient(httplib2.Http):
def __init__(self, username=None, tenant_id=None, tenant_name=None,
password=None, auth_url=None, region_name=None, timeout=None,
endpoint=None, token=None, cacert=None, key=None,
- cert=None, insecure=False):
+ cert=None, insecure=False, original_ip=None):
super(HTTPClient, self).__init__(timeout=timeout, ca_certs=cacert)
if cert:
if key:
@@ -54,6 +54,7 @@ class HTTPClient(httplib2.Http):
self.version = 'v2.0'
self.region_name = region_name
self.auth_token = token
+ self.original_ip = original_ip
self.management_url = endpoint
@@ -117,6 +118,9 @@ class HTTPClient(httplib2.Http):
request_kwargs = copy.copy(kwargs)
request_kwargs.setdefault('headers', kwargs.get('headers', {}))
request_kwargs['headers']['User-Agent'] = self.USER_AGENT
+ if self.original_ip:
+ request_kwargs['headers']['Forwarded'] = "for=%s;by=%s" % (
+ self.original_ip, self.USER_AGENT)
if 'body' in kwargs:
request_kwargs['headers']['Content-Type'] = 'application/json'
request_kwargs['body'] = json.dumps(kwargs['body'])