Skip to content

Commit a43909a

Browse files
authored
Merge pull request #173 from lykinsbd/fix_proxies
Resolve #172, Enable HTTP Proxy Support for `iControlRESTTokenAuth` Object
2 parents 34bb916 + 3961c2e commit a43909a

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
.idea/*
77
*.py[cod]
88

9+
### Additional virtual environment files
10+
bin/
11+
pyvenv.cfg
12+
913
### added with RM's Makefile
1014
localutils/**
1115
agent/f5/bigip/pycontrol/wsdl/**

icontrol/authtoken.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class iControlRESTTokenAuth(AuthBase):
5555
BigIP should consult when creating the token.
5656
:param str verify: The path to a CA bundle containing the \
5757
CA certificate for SSL validation
58+
:param proxies: A dict of proxy information for Requests to utilize \
59+
on this connection to the BigIP
5860
5961
If ``username`` is configured locally on the BigIP,
6062
``login_provider_name`` should be ``"tmos"`` (default). Otherwise
@@ -63,10 +65,11 @@ class iControlRESTTokenAuth(AuthBase):
6365
of ``login_provider_name``.
6466
"""
6567
def __init__(self, username, password, login_provider_name='tmos',
66-
verify=False, auth_provider=None):
68+
verify=False, auth_provider=None, proxies=None):
6769
self.username = username
6870
self.password = password
6971
self.login_provider_name = login_provider_name
72+
self.proxies = proxies
7073
self.token = None
7174
self.expiration = None
7275
self.attempts = 0
@@ -95,7 +98,7 @@ def get_auth_providers(self, netloc):
9598
"""
9699
url = "https://%s/info/system?null" % (netloc)
97100

98-
response = requests.get(url, verify=self.verify)
101+
response = requests.get(url, verify=self.verify, proxies=self.proxies)
99102
if not response.ok or not hasattr(response, "json"):
100103
error_message = '%s Unexpected Error: %s for uri: %s\nText: %r' %\
101104
(response.status_code,
@@ -147,7 +150,8 @@ def get_new_token(self, netloc):
147150
login_url,
148151
json=login_body,
149152
verify=self.verify,
150-
auth=HTTPBasicAuth(self.username, self.password)
153+
auth=HTTPBasicAuth(self.username, self.password),
154+
proxies=self.proxies,
151155
)
152156
self.attempts += 1
153157
if not response.ok or not hasattr(response, "json"):

icontrol/session.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,22 +428,22 @@ def __init__(self, username, password, **kwargs):
428428

429429
# Handle token-based auth.
430430
if token_to_use:
431-
self.session.auth = iControlRESTTokenAuth('admin', 'admin')
431+
self.session.auth = iControlRESTTokenAuth('admin', 'admin', proxies=proxies)
432432
self.session.auth.token = token_to_use
433433
else:
434434
if auth_provider:
435435
self.session.auth = iControlRESTTokenAuth(
436-
username, password, auth_provider=auth_provider, verify=verify
436+
username, password, auth_provider=auth_provider, verify=verify, proxies=proxies
437437
)
438438
else:
439439
if token_auth is True:
440440
self.session.auth = iControlRESTTokenAuth(
441-
username, password, verify=verify
441+
username, password, verify=verify, proxies=proxies
442442
)
443443
elif token_auth:
444444
# Truthy but not true: non-default loginAuthProvider
445445
self.session.auth = iControlRESTTokenAuth(
446-
username, password, token_auth, verify=verify
446+
username, password, token_auth, verify=verify, proxies=proxies
447447
)
448448
else:
449449
self.session.auth = (username, password)

0 commit comments

Comments
 (0)