# Server proxy for client parcel wfs

* refactors map_proxy.py
* adds proxy support for parcel wfs
pull/293/head
mpeltriaux 2 years ago
parent 9b3dba9eab
commit 51db1b2f5d

@ -11,3 +11,6 @@ PROXIES = {
"http": proxy, "http": proxy,
"https": proxy, "https": proxy,
} }
CLIENT_PROXY_AUTH_USER = "CHANGE_ME"
CLIENT_PROXY_AUTH_PASSWORD = "CHANGE_ME"

@ -22,7 +22,7 @@ from konova.sso.sso import KonovaSSOClient
from konova.views.logout import logout_view from konova.views.logout import logout_view
from konova.views.geometry import get_geom_parcels, get_geom_parcels_content from konova.views.geometry import get_geom_parcels, get_geom_parcels_content
from konova.views.home import home_view from konova.views.home import home_view
from konova.views.map_proxy import map_client_proxy_view from konova.views.map_proxy import ClientProxyParcelSearch, ClientProxyParcelWFS
sso_client = KonovaSSOClient(SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY) sso_client = KonovaSSOClient(SSO_SERVER, SSO_PUBLIC_KEY, SSO_PRIVATE_KEY)
urlpatterns = [ urlpatterns = [
@ -40,7 +40,8 @@ urlpatterns = [
path('api/', include("api.urls")), path('api/', include("api.urls")),
path('geom/<id>/parcels/', get_geom_parcels, name="geometry-parcels"), path('geom/<id>/parcels/', get_geom_parcels, name="geometry-parcels"),
path('geom/<id>/parcels/<int:page>', get_geom_parcels_content, name="geometry-parcels-content"), path('geom/<id>/parcels/<int:page>', get_geom_parcels_content, name="geometry-parcels-content"),
path('client/proxy', map_client_proxy_view, name="map-client-proxy"), path('client/proxy', ClientProxyParcelSearch.as_view(), name="client-proxy-search"),
path('client/proxy/wfs', ClientProxyParcelWFS.as_view(), name="client-proxy-wfs"),
] ]
if DEBUG: if DEBUG:

@ -10,31 +10,80 @@ import json
import requests import requests
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.http import JsonResponse, HttpRequest from django.http import JsonResponse, HttpRequest
from django.utils.decorators import method_decorator
from django.utils.http import urlencode
from django.views import View
from requests.auth import HTTPDigestAuth
from konova.sub_settings.proxy_settings import PROXIES from konova.sub_settings.proxy_settings import PROXIES, CLIENT_PROXY_AUTH_USER, CLIENT_PROXY_AUTH_PASSWORD
@login_required class BaseClientProxyView(View):
def map_client_proxy_view(request: HttpRequest):
""" Provides proxy functionality for NETGIS map client. """ Provides proxy functionality for NETGIS map client.
Used for fetching content of a provided url """
class Meta:
abstract = True
Args: @method_decorator(login_required)
request (HttpRequest): The incoming request def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)
Returns: def perform_url_call(self, url, headers={}, auth=None):
""" Generic proxied call
""" Args:
url = request.META.get("QUERY_STRING") url (str): The url to call
response = requests.get(url, proxies=PROXIES) headers (dict): Optional headers
content = response.content auth: Optional authentication info
if isinstance(content, bytes):
content = content.decode("utf-8") Returns:
body = json.loads(content)
if response.status_code != 200: """
return JsonResponse({ response = requests.get(
"status_code": response.status_code, url,
"content": body, proxies=PROXIES,
}) headers=headers,
return JsonResponse(body) auth=auth
)
content = response.content
if isinstance(content, bytes):
content = content.decode("utf-8")
return content, response.status_code
class ClientProxyParcelSearch(BaseClientProxyView):
def get(self, request: HttpRequest):
url = request.META.get("QUERY_STRING")
content, response_code = self.perform_url_call(url)
body = json.loads(content)
if response_code != 200:
return JsonResponse({
"status_code": response_code,
"content": body,
})
return JsonResponse(body)
class ClientProxyParcelWFS(BaseClientProxyView):
def get(self, request: HttpRequest):
params = request.GET.dict()
params["version"] = "2.0.0"
params["outputformat"] = "application/json; subtype=geojson"
base_url = "https://www.geoportal.rlp.de/registry/wfs/519"
url = f"{base_url}?{urlencode(params, doseq=True)}"
url = url.replace("typename", "typenames")
auth = HTTPDigestAuth(CLIENT_PROXY_AUTH_USER, CLIENT_PROXY_AUTH_PASSWORD)
content, response_code = self.perform_url_call(url, auth=auth)
body = json.loads(content)
if response_code != 200:
return JsonResponse({
"status_code": response_code,
"content": body,
})
resp = JsonResponse(body)
return resp

@ -29,6 +29,7 @@
{ "folder": 1, "type": "WMS", "title": "Lagebezeichnungen", "url": "https://geo5.service24.rlp.de/wms/liegenschaften_rp.fcgi?", "name": "Lagebezeichnungen" }, { "folder": 1, "type": "WMS", "title": "Lagebezeichnungen", "url": "https://geo5.service24.rlp.de/wms/liegenschaften_rp.fcgi?", "name": "Lagebezeichnungen" },
{ "folder": 1, "type": "WMS", "title": "Flurstücke", "url": "https://geo5.service24.rlp.de/wms/liegenschaften_rp.fcgi?", "name": "Flurstueck", "active": true}, { "folder": 1, "type": "WMS", "title": "Flurstücke", "url": "https://geo5.service24.rlp.de/wms/liegenschaften_rp.fcgi?", "name": "Flurstueck", "active": true},
{ "folder": 1, "type": "WFS", "title": "Flurstücke (WFS)", "url": "/client/proxy/wfs?", "name": "ave:Flurstueck"},
{ "folder": 1, "type": "WMS", "title": "Gebäude / Bauwerke", "url": "https://geo5.service24.rlp.de/wms/liegenschaften_rp.fcgi?", "name": "GebaeudeBauwerke" }, { "folder": 1, "type": "WMS", "title": "Gebäude / Bauwerke", "url": "https://geo5.service24.rlp.de/wms/liegenschaften_rp.fcgi?", "name": "GebaeudeBauwerke" },
{ "folder": 1, "type": "WMS", "title": "Nutzung", "url": "https://geo5.service24.rlp.de/wms/liegenschaften_rp.fcgi?", "name": "Nutzung" }, { "folder": 1, "type": "WMS", "title": "Nutzung", "url": "https://geo5.service24.rlp.de/wms/liegenschaften_rp.fcgi?", "name": "Nutzung" },

Loading…
Cancel
Save