Skip to content

Commit

Permalink
Merge pull request #270 from lsst-ts/tickets/DM-44922
Browse files Browse the repository at this point in the history
Update core dependencies and remove final traces of the Authlist feature
  • Loading branch information
sebastian-aranda authored Aug 7, 2024
2 parents 9a7ec6a + 9e38a3b commit 8683fa3
Show file tree
Hide file tree
Showing 18 changed files with 165 additions and 150 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Version History
===============

v7.0.0
------

* Update core dependencies and remove final traces of the Authlist feature `<https://github.com/lsst-ts/LOVE-manager/pull/270>`_

v6.0.8
------

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ All these variables are initialized with default variables defined in :code:`.en
- `ADMIN_USER_PASS`: password for the default `admin` user, which has every permission.
- `USER_USER_PASS`: password for the default `user` user, which has readonly permissions and cannot execute commands.
- `CMD_USER_PASS`: password for the default `cmd` user, which has readonly permissions but can execute commands.
- `AUTHLIST_USER_PASS`: password for the default `authlist` user, which has permissions to manage the authlist authorization requests.
- `SECRET_KEY`: overrides Django's SECRET_KEY, if not defined the default value (public in this repo) will be used.
- `REDIS_HOST`: the location of the redis host that implements the `Channels Layer`.
- `REDIS_PASS`: the password that the LOVE-manager needs to use to connect with `redis`.
Expand Down
3 changes: 1 addition & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
FROM python:3.8.2-buster
FROM python:3.11-bookworm

# Install required packages
RUN apt-get update && \
apt-get install -y \
libsasl2-dev \
python-dev \
libldap2-dev \
libssl-dev &&\
rm -rf /var/lib/apt/lists/*
Expand Down
3 changes: 1 addition & 2 deletions docker/Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
FROM python:3.8.2-buster
FROM python:3.11-bookworm

# Install required packages
RUN apt-get update && \
apt-get install -y \
libsasl2-dev \
python-dev \
libldap2-dev \
libssl-dev &&\
rm -rf /var/lib/apt/lists/*
Expand Down
3 changes: 1 addition & 2 deletions docker/Dockerfile-static
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
FROM python:3.8.2-buster as builder
FROM python:3.11-bookworm as builder

# Install required packages
RUN apt-get update && \
apt-get install -y \
libsasl2-dev \
python-dev \
libldap2-dev \
libssl-dev &&\
rm -rf /var/lib/apt/lists/*
Expand Down
24 changes: 0 additions & 24 deletions docker/Dockerfile-tasks

This file was deleted.

3 changes: 1 addition & 2 deletions docker/Dockerfile-test
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
FROM python:3.8.2-buster
FROM python:3.11-bookworm

# Install required packages
RUN apt-get update && \
apt-get install -y \
libsasl2-dev \
python-dev \
libldap2-dev \
libssl-dev &&\
rm -rf /var/lib/apt/lists/*
Expand Down
2 changes: 1 addition & 1 deletion manager/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from django.conf import settings
from django.core.exceptions import ValidationError
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


class BaseModel(models.Model):
Expand Down
19 changes: 16 additions & 3 deletions manager/manager/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,23 @@
# this program. If not, see <http://www.gnu.org/licenses/>.


"""Defines the rules for routing of channels messages (websockets) in the whole project."""
from channels.routing import ProtocolTypeRouter, URLRouter
"""Defines the rules for routing of
channels messages (websockets) in the whole project."""
import subscription.routing
from channels.routing import ProtocolTypeRouter, URLRouter
from django.core.asgi import get_asgi_application
from subscription.auth import TokenAuthMiddleware

# Initialize Django ASGI application early to ensure the AppRegistry
# is populated before importing code that may import ORM models.
django_asgi_app = get_asgi_application()

application = ProtocolTypeRouter(
{"websocket": URLRouter(subscription.routing.websocket_urlpatterns)}
{
# Django's ASGI application to handle traditional HTTP requests
"http": django_asgi_app,
"websocket": TokenAuthMiddleware(
URLRouter(subscription.routing.websocket_urlpatterns)
),
}
)
4 changes: 4 additions & 0 deletions manager/manager/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
else "django.core.files.storage.FileSystemStorage"
)

# Define the default auto field for Django models
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Expand Down Expand Up @@ -106,6 +109,7 @@

# Application definition
INSTALLED_APPS = [
"daphne",
"django.contrib.auth",
"django.contrib.admin",
"django.contrib.contenttypes",
Expand Down
47 changes: 24 additions & 23 deletions manager/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
aioredis==1.3.1
aioredis==2.0.1
alabaster==0.7.12
asgiref==3.3.1
asgiref==3.8.1
asn1crypto==1.3.0
astropy==5.0.3
astropy==5.3.4
async-timeout==3.0.1
atomicwrites==1.4.1
attrs==22.1.0
autobahn==20.12.3
autobahn==23.6.2
Automat==20.2.0
Babel==2.9.1
certifi==2023.7.22
cffi==1.14.0
channels==3.0.3
channels-redis==3.2.0
cffi==1.16.0
channels==4.1.0
channels-redis==4.2.0
chardet==3.0.4
constantly==15.1.0
coreapi==2.3.3
coreschema==0.0.4
cryptography==42.0.4
Django==3.2.25
django-auth-ldap==4.1.0
django-cors-headers==3.2.1
daphne==4.1.2
Django==5.0.7
django-auth-ldap==4.8.0
django-cors-headers==4.4.0
django-webpack-loader==0.7.0
djangorestframework==3.11.2
djangorestframework==3.15.2
docutils==0.16
drf-yasg==1.17.1
drf-yasg==1.21.7
entrypoints==0.3
freezegun==0.3.15
hiredis==1.0.1
hyperlink==19.0.0
hiredis==3.0.0
hyperlink==21.0.0
idna==2.9
imagesize==1.2.0
importlib-metadata==1.5.0
incremental==17.5.0
incremental==22.10.0
inflection==0.3.1
itypes==1.1.0
Jinja2==2.11.3
Expand All @@ -43,11 +44,11 @@ mistune<2.0.0
more-itertools==8.2.0
msgpack==1.0.0
numpy==1.22.0
packaging==20.3
packaging==24.1
pip-licenses==2.1.1
Pillow==10.0.1
pluggy==0.13.1
psycopg2==2.8.4
psycopg2==2.9.9
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycodestyle==2.5.0
Expand All @@ -63,19 +64,19 @@ pytest-django==4.5.2
pytest-env==0.8.1
python-dateutil==2.8.1
python-ldap==3.4.0
pytz==2019.3
PyYAML==5.4
pytz==2024.1
PyYAML==6.0.1
requests==2.31.0
ruamel.yaml==0.16.10
ruamel.yaml.clib==0.2.0
ruamel.yaml==0.18.6
ruamel.yaml.clib==0.2.8
six==1.14.0
snowballstemmer==2.0.0
sqlparse==0.4.4
Twisted==23.10.0
txaio==20.1.1
txaio==23.1.1
uritemplate==3.0.1
urllib3==1.26.18
uvicorn[standard]==0.24.0.post1
wcwidth==0.1.8
zipp==3.1.0
zope.interface==4.7.2
zope.interface==6.4
2 changes: 1 addition & 1 deletion manager/runserver-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ echo -e "\nApplying migrations"
python manage.py migrate

echo -e "\nCreating default users"
python manage.py createusers --adminpass ${ADMIN_USER_PASS} --userpass ${USER_USER_PASS} --cmduserpass ${CMD_USER_PASS} --authlistuserpass ${AUTHLIST_USER_PASS}
python manage.py createusers --adminpass ${ADMIN_USER_PASS} --userpass ${USER_USER_PASS} --cmduserpass ${CMD_USER_PASS}
if [ -z ${LOVE_SITE} ]; then
love_site="summit"
else
Expand Down
2 changes: 1 addition & 1 deletion manager/runserver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ echo -e "\nApplying migrations"
python manage.py migrate

echo -e "\nCreating default users"
python manage.py createusers --adminpass ${ADMIN_USER_PASS} --userpass ${USER_USER_PASS} --cmduserpass ${CMD_USER_PASS} --authlistuserpass ${AUTHLIST_USER_PASS}
python manage.py createusers --adminpass ${ADMIN_USER_PASS} --userpass ${USER_USER_PASS} --cmduserpass ${CMD_USER_PASS}
if [ -z ${LOVE_SITE} ]; then
love_site="summit"
else
Expand Down
54 changes: 21 additions & 33 deletions manager/subscription/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@

"""Defines the TokenAuthMiddleware used for token authentication."""
import urllib.parse as urlparse

from api.models import Token
from channels.db import database_sync_to_async
from django.contrib.auth.models import AnonymousUser
from django.db import close_old_connections
from channels.db import database_sync_to_async
from api.models import Token


@database_sync_to_async
Expand All @@ -38,56 +39,43 @@ def get_user(token):
Returns
-------
`User`
The User associated to the token, or AnonymousUser if the token was not found.
The User associated to the token,
or AnonymousUser if the token was not found.
"""
if not token:
return AnonymousUser()

token_obj = Token.objects.filter(key=token).first()
if token_obj:
return token_obj.user
else:
return AnonymousUser()
return AnonymousUser()


class TokenAuthMiddleware:
"""Custom middleware to use a token for user authentication on websockets connections."""
"""Custom middleware to use a token
for user authentication on websockets connections."""

def __init__(self, inner):
self.inner = inner
def __init__(self, app):
# Store the ASGI application we were passed
self.app = app

def __call__(self, scope):
async def __call__(self, scope, receive, send):
"""Verify if the user is authenticated.
Parameters
----------
scope: `dict`
scope : `dict`
dictionary defining parameters for the authentication
"""
return TokenAuthMiddlewareInstance(scope, self)
receive : `function`
function to receive messages from the client
class TokenAuthMiddlewareInstance:
"""Class that builds the instance of the TokenAuthMiddleware."""

def __init__(self, scope, middleware):
self.middleware = middleware
self.scope = dict(scope)
self.inner = self.middleware.inner

async def __call__(self, receive, send):
"""Verify if the user is authenticated.
Parameters
----------
scope: `dict`
dictionary defining parameters for the authentication
send : `function`
function to send messages to the client
"""
close_old_connections()
query_string = self.scope.get("query_string").decode()
query_string = scope.get("query_string").decode()
data = urlparse.parse_qs(query_string)
self.scope["user"] = await get_user(
data["token"][0] if "token" in data else None
)
self.scope["password"] = data["password"][0] if "password" in data else None
return await self.inner(self.scope, receive, send)
scope["user"] = await get_user(data["token"][0] if "token" in data else None)
scope["password"] = data["password"][0] if "password" in data else None
return await self.app(scope, receive, send)
Loading

0 comments on commit 8683fa3

Please sign in to comment.