Skip to content
Snippets Groups Projects
Commit e6ed9771 authored by Sébastien DA ROCHA's avatar Sébastien DA ROCHA :bicyclist: Committed by m431m
Browse files

First version of rproxy

parent dd9d35c2
No related branches found
No related tags found
1 merge request!2REDMINE_ISSUE-14039 authentification proxy for Mapstore
# Copyright (c) 2021-2022 Neogeo-Technologies.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
default_app_config = 'onegeo_rproxy_mapstore2.apps.OnegeoRproxyMapstore2Config'
# from django/utils/version.py
import datetime # noqa E402
import functools # noqa E402
import logging # noqa E402
import os # noqa E402
import os.path # noqa E402
import subprocess # noqa E402
logger = logging.getLogger(__name__)
@functools.lru_cache()
def get_git_changeset():
"""Return a numeric identifier of the latest git changeset.
The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format.
This value isn't guaranteed to be unique, but collisions are very unlikely,
so it's sufficient for generating the development version numbers.
"""
# Repository may not be found if __file__ is undefined, e.g. in a frozen
# module.
if '__file__' not in globals():
return None
repo_dir = os.path.dirname(os.path.abspath(__file__))
git_log = subprocess.run(
'git log --pretty=format:%ct --quiet -1 HEAD',
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
shell=True, cwd=repo_dir, universal_newlines=True,
)
timestamp = git_log.stdout
try:
timestamp = datetime.datetime.utcfromtimestamp(int(timestamp))
except ValueError as err:
logger.exception(err)
return ''
return timestamp.strftime('%Y%m%d%H%M%S')
def get_version(version=None):
assert len(version) == 5
assert version[3] in ('dev', 'beta', 'rc', 'final')
main = '.'.join(str(x) for x in version[:3])
sub = ''
if version[3] == 'dev' and version[4] == 0:
git_changeset = get_git_changeset()
if git_changeset:
sub = '.dev%s' % git_changeset
elif version[3] != 'final':
mapping = {'beta': 'b', 'rc': 'rc'}
sub = mapping[version[3]] + str(version[4])
return main + sub
VERSION = (1, 0, 0, 'beta', 0)
__version__ = get_version(VERSION)
# Copyright (c) 2021-2022 Neogeo-Technologies.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import logging
from django.utils.translation import gettext_lazy as _
from onegeo_suite.apps import OnegeoBaseConfig
logger = logging.getLogger(__name__)
class OnegeoRproxyMapstore2Config(OnegeoBaseConfig):
name = 'onegeo_rproxy_mapstore2'
verbose_name = _("RProxy MapStore2")
APP_DEPENDENCIES = [
'onegeo_suite',
]
MANDATORY_SETTINGS = [
'ONEGEOSUITE_MAPSTORE_UPSTREAM',
'ONEGEOSUITE_MAPSTORE_AUTH_HEADER',
]
# Copyright (c) 2021-2022 Neogeo-Technologies.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import logging
from django.conf import settings
from drfreverseproxy.views import ProxyView
from rest_framework import permissions
logger = logging.getLogger(__name__)
ONEGEOSUITE_MAPSTORE_UPSTREAM = settings.ONEGEOSUITE_MAPSTORE_UPSTREAM
ONEGEOSUITE_MAPSTORE_AUTH_HEADER = settings.ONEGEOSUITE_MAPSTORE_AUTH_HEADER
class MapstoreProxyView(ProxyView):
upstream = ONEGEOSUITE_MAPSTORE_UPSTREAM
permission_classes = [
permissions.AllowAny,
]
def get_request_headers(self):
"""
Place le nom utilisateur dans un Header HTTP pour que Mapstore puisse
l'autentifier. Ne positionne pas ce header si l'utilisateur est
anonyme.
Supprime le contenu de ce header si il existe déjà pour éviter qu'un
attaquant externe puisse prendre l'identité d'un utilisateur.
"""
# Les headers du META ont le prefix HTTP_ et sont en uppercase
auth_user = 'HTTP_' + ONEGEOSUITE_MAPSTORE_AUTH_HEADER.replace('-', '_').upper()
self.request.META.pop(auth_user, None)
headers = super().get_request_headers()
if not self.request.user.is_anonymous:
headers[ONEGEOSUITE_MAPSTORE_AUTH_HEADER] = self.request.user.username
return headers
# Copyright (c) 2021-2022 Neogeo-Technologies.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from django.urls import re_path
from onegeo_rproxy_mapstore2.rproxy import MapstoreProxyView
app_name = 'onegeo_rproxy_mapstore2'
urlpatterns = [
re_path(r'^(?P<path>(.*))$', MapstoreProxyView.as_view(), name='rproxy_mapstore2'),
]
# django-onegeo-suite>=1.0.0
\ No newline at end of file
setup.py 0 → 100644
# Copyright (c) 2017-2020 Neogeo-Technologies.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os.path
from setuptools import find_packages
from setuptools import setup
from onegeo_rproxy_mapstore2 import __version__
def parse_requirements(filename):
with open(filename) as f:
lines = (line.strip() for line in f)
return [line for line in lines if line and not line.startswith('#')]
dirname = os.path.dirname(__file__)
reqs_filename = os.path.join(dirname, 'requirements.txt')
reqs = [str(req) for req in parse_requirements(reqs_filename)]
setup(
name='django-onegeo-rproxy-mapstore2',
version=__version__,
description="Onegeo Reverse Proxy for Mapstore2",
author="Neogeo Technologies",
author_email="contact@neogeo.fr",
url="https://git.neogeo.fr/onegeo-suite/apps/django-onegeo-rproxy-mapstore2",
license="Apache License, Version 2.0",
classifiers=[
"License :: OSI Approved :: Apache Software License",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
],
packages=find_packages(where='.'),
install_requires=reqs,
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment