Skip to content

Commit 4da773f

Browse files
committed
Dockerizing , Add Knox Authentication
1 parent bbbd06a commit 4da773f

21 files changed

+148
-1756
lines changed

Dockerfile

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM python:3.8-slim-buster
2+
3+
ENV PYTHONUNBUFFERED=1
4+
RUN apt-get update \
5+
# dependencies for building Python packages
6+
&& apt-get install -y build-essential \
7+
# psycopg2 dependencies
8+
&& apt-get install -y libpq-dev \
9+
# Translations dependencies
10+
&& apt-get install -y gettext \
11+
# cleaning up unused files
12+
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
16+
RUN mkdir /code
17+
WORKDIR /code
18+
19+
COPY requirements.txt /code/
20+
21+
RUN pip install -r requirements.txt
22+
COPY . /code/
23+
24+
ENTRYPOINT ["bash","entrypoint.sh"]

GhugAPI/settings.py

+20-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from datetime import timedelta
1616
from environs import Env
1717
import dj_database_url
18-
18+
#from rest_framework.settings import api_settings
1919
env = Env()
2020
env.read_env()
2121
# Build paths inside the project like this: BASE_DIR / 'subdir'.
@@ -31,7 +31,7 @@
3131
# SECURITY WARNING: don't run with debug turned on in production!
3232
#DEBUG = bool(env("DEBUG", default=False))
3333

34-
DEBUG = TRUE
34+
DEBUG = False
3535
ALLOWED_HOSTS = ['https://test-ghug.azurewebsites.net','test-ghug.azurewebsites.net', 'localhost', '127.0.0.1']
3636
#ALLOWED_HOSTS=['*']
3737
CSRF_TRUSTED_ORIGINS = ['https://test-ghug.azurewebsites.net']
@@ -49,14 +49,14 @@
4949
#3rd-party-apps
5050
'rest_framework',
5151
'corsheaders',
52-
'rest_framework_simplejwt.token_blacklist',
52+
#'rest_framework_simplejwt.token_blacklist',
53+
'knox',
5354

5455
#local apps
5556
'users.apps.UsersConfig',
5657
'news.apps.NewsConfig',
5758
'reminders.apps.RemindersConfig',
5859
'baby.apps.BabyConfig',
59-
'crymodel.apps.CrymodelConfig',
6060
]
6161
AUTH_USER_MODEL = 'users.CustomUser'
6262

@@ -162,12 +162,26 @@
162162
'rest_framework.permissions.AllowAny',
163163
],
164164
'DEFAULT_AUTHENTICATION_CLASSES': [
165-
'rest_framework_simplejwt.authentication.JWTAuthentication',
165+
#'rest_framework_simplejwt.authentication.JWTAuthentication',
166+
'knox.auth.TokenAuthentication',
166167
'rest_framework.authentication.SessionAuthentication',
167168
],
168169
}
169170

171+
#MODELS = str(BASE_DIR.joinpath('ML/models'))
172+
173+
REST_KNOX = {
174+
'SECURE_HASH_ALGORITHM': 'cryptography.hazmat.primitives.hashes.SHA512',
175+
'AUTH_TOKEN_CHARACTER_LENGTH': 64,
176+
'TOKEN_TTL': timedelta(days=1000),
177+
'USER_SERIALIZER': 'knox.serializers.UserSerializer',
178+
'TOKEN_LIMIT_PER_USER': None,
179+
'AUTO_REFRESH': False,
180+
#'EXPIRY_DATETIME_FORMAT': api_settings.DATETME_FORMAT,
181+
}
182+
170183

184+
"""
171185
SIMPLE_JWT = {
172186
'ACCESS_TOKEN_LIFETIME': timedelta( days= 40),
173187
'REFRESH_TOKEN_LIFETIME': timedelta(days=100),
@@ -182,6 +196,4 @@
182196
'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
183197
'TOKEN_TYPE_CLAIM': 'token_type',
184198
}
185-
186-
187-
199+
"""

GhugAPI/urls.py

-5
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
from django.contrib import admin
1717
from django.urls import path ,include
1818
from .router import router
19-
from rest_framework_simplejwt.views import (
20-
#TokenObtainPairView,
21-
TokenRefreshView,
22-
)
2319

2420

2521

@@ -28,6 +24,5 @@
2824
path('', include(router.urls)),
2925
path('api-auth/', include('rest_framework.urls')),
3026
path('users/', include('users.urls')),
31-
3227

3328
]

crymodel/__init__.py

Whitespace-only changes.

crymodel/admin.py

-3
This file was deleted.

crymodel/apps.py

-6
This file was deleted.

crymodel/migrations/__init__.py

Whitespace-only changes.

crymodel/models.py

-3
This file was deleted.

crymodel/tests.py

-3
This file was deleted.

crymodel/views.py

-3
This file was deleted.

docker-compose.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: "3.3"
2+
3+
services:
4+
django:
5+
build:
6+
context : .
7+
env_file:
8+
- .env
9+
volumes:
10+
- .:/code
11+
ports:
12+
- "8000:8000"
13+

entrypoint.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
python manage.py migrate
4+
5+
python manage.py runserver 0.0.0.0:8000

models/loadmodel.ipynb

-117
This file was deleted.

0 commit comments

Comments
 (0)