diff --git a/.gitignore b/.gitignore index 0ea401c..f7fce91 100644 --- a/.gitignore +++ b/.gitignore @@ -17,5 +17,5 @@ wheelhouse/ .vagrant/ .cache/ rcs.egg-info/ - +local/ MANIFEST diff --git a/config.py b/config.py index a322afe..39d71a5 100644 --- a/config.py +++ b/config.py @@ -23,4 +23,5 @@ DEBUG_ENDPOINTS = True PROD = False -# FEATURE_SERVICE_PROXY='http://127.0.0.1:8001' +#Leave blank if no proxy required +HTTP_PROXY = 'http://localhost:8899' diff --git a/docs/admin/configuration.rst b/docs/admin/configuration.rst index 8adb894..5444283 100644 --- a/docs/admin/configuration.rst +++ b/docs/admin/configuration.rst @@ -13,8 +13,6 @@ LOG_ROTATE_BYTES Size in bytes at which logs should be rotated ACCESS_LOG Name of the access log file, if not present access requests will not be logged -FEATURE_SERVICE_PROXY - A proxy URL to be used when registering ESRI feature layers. Should be in the form of ``http://[server]:[port]``. URL_PREFIX A general prefix for the application, useful if you want to have side by side installs of RCS. It should include an opening / (e.g. ``/rcs_ecdmp``). @@ -34,3 +32,5 @@ REG_SCHEMA Path to the JSON schema to be used for validating PUT requests LANGS Must match the languages required by the schema (e.g. 'en', 'fr') +HTTP_PROXY + A proxy URL to be used when registering layers. Should be in the form of ``http://[server]:[port]``. diff --git a/run.py b/run.py index 476f471..1d60ba0 100644 --- a/run.py +++ b/run.py @@ -62,6 +62,9 @@ def log_response(sender, response): def before_request(): flask.g.get_validator = lambda: jsonschema.validators.Draft4Validator(json.load(open(schema_path))) # TODO this is probably a good place to attach proxies for feature retrieval + global _proxies + _proxies = { 'http': app.config['HTTP_PROXY'], 'https': app.config['HTTP_PROXY']} + if app.config.get('DEBUG_ENDPOINTS'): @app.after_request diff --git a/services/regparse/esri.py b/services/regparse/esri.py index 85a5e94..4f81e5e 100644 --- a/services/regparse/esri.py +++ b/services/regparse/esri.py @@ -4,10 +4,10 @@ Most of the utility functions are exposed but most applications won't use them :func:make_node is generally the only point of interest here. """ -import requests +import requests, config # TODO test me - +_proxies = {'http': config.HTTP_PROXY, 'https': config.HTTP_PROXY} def make_grid_col(**kw): """ @@ -89,7 +89,7 @@ def get_legend_mapping(feature_url, layer_id): :param layer_id: The id of the layer to create the mapping for. :returns: dict -- a mapping of 'label' => 'data URI encoded image' """ - legend_json = requests.get(get_legend_url(feature_url)).json() + legend_json = requests.get(get_legend_url(feature_url), proxies=_proxies).json() for layer in legend_json['layers']: if layer['layerId'] == layer_id: break @@ -187,8 +187,7 @@ def make_v1_feature_node(json_request, v2_node): """ steal_fields = ['id', 'url', 'metadataUrl', 'catalogueUrl'] node = {field: v2_node[field] for field in steal_fields if field in v2_node} - - r = requests.get(v2_node['url'] + '?f=json') + r = requests.get(v2_node['url'] + '?f=json', proxies=_proxies ) svc_data = r.json() node['displayName'] = json_request.get('service_name', None) node['nameField'] = json_request.get('display_field', None) diff --git a/services/regparse/universal.py b/services/regparse/universal.py index b13255c..b27a175 100644 --- a/services/regparse/universal.py +++ b/services/regparse/universal.py @@ -1,8 +1,8 @@ -import metadata, requests, ogc, esri, re +import metadata, requests, ogc, esri, re, config remapped_types = {'esriMapServer': 'esriDynamic', 'esriFeatureServer': 'esriDynamic'} - +_proxies = {'http': config.HTTP_PROXY, 'https': config.HTTP_PROXY} class ServiceTypes: WMS = 'ogcWms' @@ -60,7 +60,7 @@ def get_endpoint_type(endpoint, type_hint=None): # FIXME type detection should be much more robust, add proper XML parsing, ... return ServiceTypes.WMS elif is_esri: - r = requests.get(endpoint+'?f=json') + r = requests.get(endpoint+'?f=json', proxies=_proxies ) data = r.json() if 'type' in data: if data['type'] == 'Feature Layer':