Skip to content

Commit 8746aca

Browse files
authored
SHOT-4398: Fix proxy handling (#83)
* Handle proxy servers for socketio communication * Add env var to optionally enable/disable proxy
1 parent c11386e commit 8746aca

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

python/tk_framework_alias/server/alias_bridge.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import logging
1212
import os
1313
import subprocess
14+
import requests
1415
import sys
1516
import threading
1617
import pprint
@@ -55,6 +56,9 @@ def __init__(self):
5556
self.__default_port = 8000
5657
self.__max_retry_count = 25
5758
self.__server_socket = None
59+
self.__proxy_trust_env = bool(
60+
os.environ.get("ALIAS_PLUGIN_CLIENT_PROXY_TRUST_ENV")
61+
)
5862

5963
# Track the clients registered to the socketio server
6064
self.__clients = {}
@@ -86,9 +90,21 @@ def __init__(self):
8690
client_sio_logger = framework_utils.get_logger(
8791
self.__class__.__name__, "sio_client"
8892
)
89-
self.__alias_events_client_sio = socketio.Client(
90-
logger=client_sio_logger, engineio_logger=client_sio_logger
91-
)
93+
94+
# Set up kwargs to pass to socketio Client
95+
client_kwargs = {
96+
"logger": client_sio_logger,
97+
"engineio_logger": client_sio_logger,
98+
}
99+
if not self.__proxy_trust_env:
100+
# Set up a session object to ignore any proxy settings specified in
101+
# environment variables
102+
session = requests.Session()
103+
session.trust_env = False
104+
client_kwargs["http_session"] = session
105+
106+
# Create the client to handle Alias events
107+
self.__alias_events_client_sio = socketio.Client(**client_kwargs)
92108
self.__alias_events_client_sio.register_namespace(AliasEventsClientNamespace())
93109
self.__server_sio.register_namespace(AliasEventsServerNamespace())
94110

python/tk_framework_alias_utils/startup.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def get_plugin_environment(
3535
entity_id=None,
3636
hostname=None,
3737
port=None,
38+
proxy_trust_env=False,
3839
debug="0",
3940
new_process=False,
4041
):
@@ -64,6 +65,8 @@ def get_plugin_environment(
6465
for the Toolkit Manager to bootstrap the engine
6566
ALIAS_PLUGIN_CLIENT_SIO_HOSTNAME - the host for the socketio server to connect to
6667
ALIAS_PLUGIN_CLIENT_SIO_PORT - the port number for the socketio server to connect to
68+
ALIAS_PLUGIN_CLIENT_PROXY_TRUST_ENV - set to trust the proxy environment variables else do not set to
69+
ignore env variables for proxy settings
6770
6871
:param alias_version: The Alias version that the plugin is running with.
6972
:type alias_version: str
@@ -76,6 +79,8 @@ def get_plugin_environment(
7679
:param python_exe: Option to specify a python.exe to run the client app with. Defaults
7780
to the sys.executable
7881
:type python_exe: str
82+
:param proxy_trust_env: True to trust env vars for proxy settings else False to ignore
83+
:type proxy_trust_env: bool
7984
:param debug: Set to "1" to run in debug mode, else "0" for non-debug mode.
8085
:type debug: str
8186
@@ -113,6 +118,9 @@ def get_plugin_environment(
113118
if port is not None:
114119
env["ALIAS_PLUGIN_CLIENT_SIO_PORT"] = str(port)
115120

121+
if proxy_trust_env:
122+
env["ALIAS_PLUGIN_CLIENT_PROXY_TRUST_ENV"] = "1"
123+
116124
return env
117125

118126

@@ -756,6 +764,7 @@ def ensure_plugin_ready(
756764
pipeline_config_id=None,
757765
entity_type=None,
758766
entity_id=None,
767+
proxy_trust_env=None,
759768
debug=None,
760769
logger=None,
761770
):
@@ -807,6 +816,8 @@ def ensure_plugin_ready(
807816
:param entity_id: If the client is running within Flow Production Tracking, set the entity id used by
808817
the Toolkit Manager to bootstrap the engine from the plugin.
809818
:type entity_id: int
819+
:param proxy_trust_env: True to use env vars for proxy settings else False to ignore
820+
:type proxy_trust_env: bool
810821
:param debug: Set to True to turn on debugging for the plugin, else False.
811822
:type debug: bool
812823
:param logger: Set a logger object to capture output from this operation.
@@ -884,6 +895,7 @@ def ensure_plugin_ready(
884895
pipeline_config_id=pipeline_config_id,
885896
entity_type=entity_type,
886897
entity_id=entity_id,
898+
proxy_trust_env=proxy_trust_env,
887899
debug=debug,
888900
server_python_exe=server_python_exe,
889901
new_process=new_process,

0 commit comments

Comments
 (0)