Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
Merge pull request #610 from CCI-Tools/544-hp-allow_proxy_config
Browse files Browse the repository at this point in the history
Use only one variable (http_proxy) for proxy URL in conf.py. The valu…
  • Loading branch information
forman authored Apr 17, 2018
2 parents 5bd1fb7 + d092991 commit 19a78af
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
introduced new error type `cate.core.types.ValidationError` for special treatment in the GUI.
* Make Cate HTTP User-Agent distinguishable [#510](https://github.com/CCI-Tools/cate/issues/510).
* Fixed broken WebAPI invocation from CLI.
* Use only one variable (http_proxy) for proxy URL in conf.py. The value of this variable is then returned when
get_config() is called. [#544](https://github.com/CCI-Tools/cate/issues/544)

## Version 2.0.0.dev8

Expand Down
4 changes: 4 additions & 0 deletions cate/conf/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def get_default_res_pattern() -> str:
return default_res_pattern


def get_http_proxy() -> str:
return get_config().get('http_proxy')


def is_default_variable(var_name: str) -> bool:
default_variables = get_config().get('default_variables', DEFAULT_VARIABLES)
return var_name in default_variables
Expand Down
8 changes: 3 additions & 5 deletions cate/conf/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@
# This prefix is used only if no specific prefix is defined for a given operation.
# default_res_pattern = 'res_{index}'

# User defined HTTP proxy settings, will replace one stored in System environment variable 'http_proxy' and/or
# optionally 'https_proxy'
# User defined HTTP proxy settings, will replace one stored in System environment variable 'http_proxy'
# Accepted proxy details formats:
# 'http://user:password@host:port'
# 'https://user:password@host:port'
# 'http://host:port'
# 'https://host:port'
# http_proxy =

# Uncomment and fill only if your Organization or Internet Service Provider provides proxy setting for HTTPS connections
# https_proxy =

# Include/exclude data sources (currently effective in Cate Desktop GUI only, not used by API, CLI).
#
# If 'included_data_sources' is a list, its entries are expected to be wildcard patterns for the identifiers of data
Expand Down
25 changes: 14 additions & 11 deletions cate/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from cate.conf import get_config_value

import logging

__author__ = "Chris Bernat (Telespazio VEGA UK Ltd)"

Expand All @@ -28,22 +31,22 @@ def initialize_proxy():
Initialize user defined proxy settings, read proxy setting from config file.
Populates value to 3rd-party libraries using proper environment variables.
"""
from cate.conf import get_config_value
from os import environ

config_key_http_proxy = 'http_proxy'
config_key_https_proxy = 'https_proxy'
http_proxy_url = get_config_value('http_proxy')

environ_key_http_proxy = 'http_proxy'
environ_key_https_proxy = 'https_proxy'
if not http_proxy_url:
log_invalid_http_url(http_proxy_url)
elif http_proxy_url.startswith('https'):
environ['https_proxy'] = http_proxy_url
elif http_proxy_url.startswith('http'):
environ['http_proxy'] = http_proxy_url
else:
log_invalid_http_url(http_proxy_url)

http_proxy_config = get_config_value(config_key_http_proxy)
if http_proxy_config:
environ[environ_key_http_proxy] = http_proxy_config

https_proxy_config = get_config_value(config_key_https_proxy)
if https_proxy_config:
environ[environ_key_https_proxy] = https_proxy_config
def log_invalid_http_url(http_proxy_url):
logging.warning('invalid proxy URL "' + str(http_proxy_url) + '"')


def configure_user_agent():
Expand Down
8 changes: 6 additions & 2 deletions cate/webapi/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def __init__(self, workspace_manager: WorkspaceManager):
def get_config(self) -> dict:
return dict(data_stores_path=conf.get_data_stores_path(),
use_workspace_imagery_cache=conf.get_use_workspace_imagery_cache(),
default_res_pattern=conf.get_default_res_pattern())
default_res_pattern=conf.get_default_res_pattern(),
http_proxy=conf.get_http_proxy())

def set_config(self, config: dict) -> None:

Expand All @@ -71,7 +72,10 @@ def set_config(self, config: dict) -> None:
# Split into config file lines
conf_lines = conf_text.split('\n')
for key, value in config.items():
new_entry = '%s = %s' % (key, repr(value))
if value:
new_entry = '%s = %s' % (key, repr(value))
else:
new_entry = '# %s =' % key
# Try replacing existing code lines starting with key
# Replace in reverse line order, because config files are interpreted top-down
indices = list(range(len(conf_lines)))
Expand Down

0 comments on commit 19a78af

Please sign in to comment.