Skip to content

Commit

Permalink
Added HTTP_PROXY support
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-bowerman committed May 3, 2016
1 parent a2a7e04 commit 8d37bdd
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ wheelhouse/
.vagrant/
.cache/
rcs.egg-info/

local/
MANIFEST
3 changes: 2 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 2 additions & 2 deletions docs/admin/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``).
Expand All @@ -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]``.
3 changes: 3 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions services/regparse/esri.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions services/regparse/universal.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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':
Expand Down

0 comments on commit 8d37bdd

Please sign in to comment.