Skip to content

Commit bcdc608

Browse files
author
momohossain
committed
Add code for proxy
1 parent 3e4205a commit bcdc608

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

irflow_client/irflow_client.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,20 @@ def _get_config_args_params(self, config_args):
954954

955955
if isinstance(config_args['address'], str):
956956
self.address = config_args['address']
957+
elif 'proxy_user' in config_args and \
958+
'proxy_pass' in config_args and \
959+
('http_proxy' in config_args or 'https_proxy' in config_args):
960+
auth_string = config_args['proxy_user'] + ':' + config_args['proxy_pass'] + '@'
961+
proxy = None
962+
if 'http_proxy' in config_args:
963+
proxy = config_args['http_proxy']
964+
if 'http_proxy_port' in config_args:
965+
proxy += ':' + config_args['http_proxy_port']
966+
elif 'https_proxy' in config_args:
967+
proxy = config_args['https_proxy']
968+
if 'https_proxy_port' in config_args:
969+
proxy += ':' + config_args['https_proxy_port']
970+
self.address = 'https://{0}'.format(auth_string) + proxy
957971
elif not config_args['address']:
958972
raise KeyError('You have the wrong or missing key or value')
959973
else:
@@ -1009,7 +1023,10 @@ def _get_config_file_params(self, config_file):
10091023

10101024
missing_options = []
10111025
# Check for missing required configuration keys
1012-
if not config.has_option('IRFlowAPI', 'address'):
1026+
if not config.has_option('IRFlowAPI', 'address') and \
1027+
not config.has_option('IRFlowAPI', 'proxy_user') and \
1028+
not config.has_option('IRFlowAPI', 'proxy_pass') and \
1029+
not (config.has_option('IRFlowAPI', 'http_proxy') or config.has_option('IRFlowAPI', 'https_proxy')):
10131030
self.logger.error(
10141031
'Configuration File "{}" does not contain the "address" option in the [IRFlowAPI] '
10151032
'section'.format(config_file)
@@ -1037,7 +1054,22 @@ def _get_config_file_params(self, config_file):
10371054
raise IRFlowClientConfigError('Missing configuration sections: {0}'.format(", ".join(missing_options)))
10381055

10391056
# Now set the configuration values on the self object.
1040-
self.address = config.get('IRFlowAPI', 'address')
1057+
if config.has_option('IRFlowAPI', 'proxy_user') and \
1058+
config.has_option('IRFlowAPI', 'proxy_pass') and \
1059+
(config.has_option('IRFlowAPI', 'http_proxy') or config.has_option('IRFlowAPI', 'https_proxy')):
1060+
auth_string = config.get('IRFlowAPI', 'proxy_user') + ':' + config.get('IRFlowAPI', 'proxy_pass') + '@'
1061+
proxy = None
1062+
if config.has_option('IRFlowAPI', 'http_proxy'):
1063+
proxy = config.get('IRFlowAPI', 'http_proxy')
1064+
if config.has_option('IRFlowAPI', 'http_proxy_port'):
1065+
proxy += ':' + config.get('IRFlowAPI', 'http_proxy_port')
1066+
elif config.has_option('IRFlowAPI', 'https_proxy'):
1067+
proxy = config.get('IRFlowAPI', 'https_proxy')
1068+
if config.has_option('IRFlowAPI', 'https_proxy_port'):
1069+
proxy += ':' + config.get('IRFlowAPI', 'https_proxy_port')
1070+
self.address = 'https://{0}'.format(auth_string) + proxy
1071+
else:
1072+
self.address = config.get('IRFlowAPI', 'address')
10411073
self.api_user = config.get('IRFlowAPI', 'api_user')
10421074
self.api_key = config.get('IRFlowAPI', 'api_key')
10431075
if config.has_option('IRFlowAPI', 'protocol'):

0 commit comments

Comments
 (0)