Skip to content

Commit a114839

Browse files
slmnhqPhilip Langdale
authored andcommitted
Add optional support for SOCKS proxies via PySocks.
1 parent d55932e commit a114839

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

python/setup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
if platform == 'darwin':
3434
install_requires += ['readline']
3535

36+
# Optional PySocks support
37+
extras_require = dict(Socks=['PySocks >= 1.5.0'])
38+
3639
setup(
3740
name = 'cm_api',
3841
version = '11.0.0', # Compatible with API v11 (CM 5.5)
@@ -43,6 +46,7 @@
4346
# Project uses simplejson, so ensure that it gets installed or upgraded
4447
# on the target machine
4548
install_requires = install_requires,
49+
extras_require = extras_require,
4650

4751
author = 'Cloudera, Inc.',
4852
author_email = 'scm-users@cloudera.org',

python/src/cm_api/http_client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,24 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
import os
1718
import cookielib
1819
import logging
1920
import posixpath
2021
import types
2122
import urllib
23+
24+
try:
25+
import socks
26+
import socket
27+
socks_server = os.environ.get("SOCKS_SERVER", None)
28+
if socks_server:
29+
host, port = socks_server.split(":")
30+
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, host, int(port))
31+
socket.socket = socks.socksocket
32+
except ImportError:
33+
pass
34+
2235
import urllib2
2336

2437
__docformat__ = "epytext"

python/src/cm_api/resource.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
import os
1718
try:
1819
import json
1920
except ImportError:
@@ -22,6 +23,15 @@
2223
import posixpath
2324
import time
2425
import socket
26+
try:
27+
import socks
28+
socks_server = os.environ.get("SOCKS_SERVER", None)
29+
if socks_server:
30+
host, port = socks_server.split(":")
31+
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, host, int(port))
32+
socket.socket = socks.socksocket
33+
except ImportError:
34+
pass
2535
import urllib2
2636

2737
LOG = logging.getLogger(__name__)

0 commit comments

Comments
 (0)