Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to not verify certificate when calling the real estate WMS #2005

Merged
merged 10 commits into from
Aug 16, 2024
2 changes: 2 additions & 0 deletions dev/config/pyramid_oereb.yml.mako
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,15 @@ pyramid_oereb:
fr: https://wms.geo.admin.ch/?SERVICE=WMS&REQUEST=GetMap&VERSION=1.3.0&STYLES=default&CRS=EPSG:2056&BBOX=2475000,1065000,2850000,1300000&WIDTH=493&HEIGHT=280&FORMAT=image/png&LAYERS=ch.swisstopo-vd.amtliche-vermessung
layer_index: 0
layer_opacity: 1.0
verify_certificate: True
jwkaltz marked this conversation as resolved.
Show resolved Hide resolved
jwkaltz marked this conversation as resolved.
Show resolved Hide resolved
plan_for_land_register_main_page:
# WMS URL to query the plan for land register specially for static extracts overview page
reference_wms:
de: https://wms.geo.admin.ch/?SERVICE=WMS&REQUEST=GetMap&VERSION=1.3.0&STYLES=default&CRS=EPSG:2056&BBOX=2475000,1065000,2850000,1300000&WIDTH=493&HEIGHT=280&FORMAT=image/png&LAYERS=ch.swisstopo-vd.amtliche-vermessung
fr: https://wms.geo.admin.ch/?SERVICE=WMS&REQUEST=GetMap&VERSION=1.3.0&STYLES=default&CRS=EPSG:2056&BBOX=2475000,1065000,2850000,1300000&WIDTH=493&HEIGHT=280&FORMAT=image/png&LAYERS=ch.swisstopo-vd.amtliche-vermessung
layer_index: 0
layer_opacity: 1.0
verify_certificate: True
visualisation:
method: pyramid_oereb.core.hook_methods.produce_sld_content
# Note: these parameters must fit to the attributes provided by the RealEstateRecord!!!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


from sqlalchemy import Column, ForeignKey
from sqlalchemy import String, Integer, Float, Date
from sqlalchemy import String, Integer, Float, Date, Boolean
from geoalchemy2.types import Geometry as GeoAlchemyGeometry
from sqlalchemy.orm import relationship
from sqlalchemy_utils import JSONType
Expand Down Expand Up @@ -174,14 +174,16 @@ class ViewService(base):
reference_wms (dict of str): The actual url which leads to the desired cartographic
representation (multilingual).
layer_index (int): Index for sorting the layering of the view services for a theme
layer_opacity (float): Opacity of a view service
layer_opacity (float): Opacity of a view servicA
jwkaltz marked this conversation as resolved.
Show resolved Hide resolved
verify_certificate (boolean): Whether the certificate of the WMS shall be verified
"""
__table_args__ = {'schema': schema_name}
__tablename__ = 'view_service'
id = Column(pk_type, primary_key=True, autoincrement=False)
reference_wms = Column(JSONType, nullable=False)
layer_index = Column(Integer, nullable=False)
layer_opacity = Column(Float, nullable=False)
verify_certificate = Column(Boolean, nullable=True)
jwkaltz marked this conversation as resolved.
Show resolved Hide resolved

return ViewService

Expand Down
3 changes: 2 additions & 1 deletion pyramid_oereb/contrib/data_sources/standard/sources/plr.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ def from_db_to_view_service_record(self, view_service_from_db, legend_entry_reco
Config.get('default_language'),
Config.get('srid'),
Config.get('proxies'),
legends=legend_entry_records
legends=legend_entry_records,
verify_certificate=view_service_from_db.verify_certificate
)
return view_service_record

Expand Down
6 changes: 4 additions & 2 deletions pyramid_oereb/core/readers/real_estate.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def read(self, params, nb_ident=None, number=None, egrid=None, geometry=None):
plan_for_land_register_config.get('layer_opacity'),
Config.get('default_language'),
Config.get('srid'),
Config.get('proxies')
Config.get('proxies'),
verify_certificate=plan_for_land_register_config.get('verify_certificate')
jwkaltz marked this conversation as resolved.
Show resolved Hide resolved
)

plan_for_land_register_main_page_config = Config.get_plan_for_land_register_main_page_config()
Expand All @@ -73,7 +74,8 @@ def read(self, params, nb_ident=None, number=None, egrid=None, geometry=None):
plan_for_land_register_main_page_config.get('layer_opacity'),
Config.get('default_language'),
Config.get('srid'),
Config.get('proxies')
Config.get('proxies'),
verify_certificate=plan_for_land_register_main_page_config.get('verify_certificate')
jwkaltz marked this conversation as resolved.
Show resolved Hide resolved
)

self._source_.read(params, nb_ident=nb_ident, number=number, egrid=egrid, geometry=geometry)
Expand Down
7 changes: 4 additions & 3 deletions pyramid_oereb/core/records/view_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ViewServiceRecord(object):
"""

def __init__(self, reference_wms, layer_index, layer_opacity, default_language,
srid, proxies=None, legends=None):
srid, proxies=None, legends=None, verify_certificate=True):
"""

Args:
Expand All @@ -91,6 +91,7 @@ def __init__(self, reference_wms, layer_index, layer_opacity, default_language,
srid (int): The SRID which is used for the WMS.
proxies (dict or None): The proxies which may be used
legends (list of LegendEntry or None): A list of all relevant legend entries.
verify_certificate (bool): indicates whether call to the WMS shall be verified
"""
self.reference_wms = reference_wms
self.image = dict() # multilingual dict with binary map images resulting from calling the wms link
Expand All @@ -105,13 +106,13 @@ def __init__(self, reference_wms, layer_index, layer_opacity, default_language,
self.default_language = default_language
self.srid = srid
self.proxies = proxies

if legends is None:
self.legends = []
else:
for legend in legends:
assert isinstance(legend.symbol, ImageRecord)
self.legends = legends
self.verify_certificate = verify_certificate

@staticmethod
def sanitize_layer_index(layer_index):
Expand Down Expand Up @@ -247,7 +248,7 @@ def download_wms_content(self, language):
if uri_validator(wms):
log.debug(f"Downloading image, url: {wms}")
try:
response = requests.get(wms, proxies=self.proxies)
response = requests.get(wms, proxies=self.proxies, verify=self.verify_certificate)
except Exception as ex:
dedicated_msg = f"An image could not be downloaded. URL was: {wms}, error was {ex}"
log.error(dedicated_msg)
Expand Down
19 changes: 11 additions & 8 deletions tests/core/records/test_view_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def test_init():
'de',
2056,
None,
None
None,
True
)
assert isinstance(record.reference_wms, dict)
assert isinstance(record.layer_index, int)
Expand All @@ -30,6 +31,7 @@ def test_init():
assert record.srid == 2056
assert record.proxies is None
assert len(record.legends) == 0
assert record.verify_certificate is True


def test_init_with_relation(pyramid_oereb_test_config):
Expand All @@ -49,7 +51,8 @@ def test_init_with_relation(pyramid_oereb_test_config):
'de',
2056,
None,
legend_records
legend_records,
True
)
assert isinstance(record.reference_wms, dict)
assert isinstance(record.layer_index, int)
Expand All @@ -63,20 +66,20 @@ def test_init_with_relation(pyramid_oereb_test_config):

def test_invalid_layer_index_arguments(pyramid_oereb_test_config):
with pytest.raises(AttributeError):
ViewServiceRecord({'de': 'http://example.com'}, -1001, 1, 'de', 2056, None, None)
ViewServiceRecord({'de': 'http://example.com'}, -1001, 1, 'de', 2056, None, None, True)
with pytest.raises(AttributeError):
ViewServiceRecord({'de': 'http://example.com'}, 1001, 1, 'de', 2056, None, None)
ViewServiceRecord({'de': 'http://example.com'}, 1001, 1, 'de', 2056, None, None, True)
with pytest.warns(UserWarning, match='Type of "layer_index" should be "int"'):
ViewServiceRecord({'de': 'http://example.com'}, 1.0, 1, 'de', 2056, None, None)
ViewServiceRecord({'de': 'http://example.com'}, 1.0, 1, 'de', 2056, None, None, True)


def test_invalid_layer_layer_opacity(pyramid_oereb_test_config):
with pytest.raises(AttributeError):
ViewServiceRecord({'de': 'http://example.com'}, 1, 2.0, 'de', 2056, None, None)
ViewServiceRecord({'de': 'http://example.com'}, 1, 2.0, 'de', 2056, None, None, True)
with pytest.raises(AttributeError):
ViewServiceRecord({'de': 'http://example.com'}, 1, -1.1, 'de', 2056, None, None)
ViewServiceRecord({'de': 'http://example.com'}, 1, -1.1, 'de', 2056, None, None, True)
with pytest.warns(UserWarning, match='Type of "layer_opacity" should be "float"'):
ViewServiceRecord({'de': 'http://example.com'}, 1, 1, 'de', 2056, None, None)
ViewServiceRecord({'de': 'http://example.com'}, 1, 1, 'de', 2056, None, None, True)


def test_check_min_max_attributes():
Expand Down
Loading