Skip to content

Commit f89f528

Browse files
authored
Merge pull request #245 from uw-it-aca/django-upgrade-new-2
Django upgrade new 2
2 parents f730f62 + 7604441 commit f89f528

File tree

145 files changed

+2376
-2949
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+2376
-2949
lines changed

.github/workflows/cicd.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ jobs:
195195
commit_hash: ${{ needs.context.outputs.commit_hash }}
196196
git_repo_branch: ${{ needs.context.outputs.git_repo_branch }}
197197
gh_auth_token: ${{ secrets.GH_AUTH_TOKEN }}
198-
app_instance: eval
198+
app_instance: dev
199199

200200
- name: 'Surface context from executed build step'
201201
id: context

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ spotseeker_web
3030
# IDE files
3131
.idea/
3232

33+
# vscode files
34+
.vscode/
35+
3336
# pipenv
3437
Pipfile
3538
Pipfile.lock

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG DJANGO_CONTAINER_VERSION=1.3.8
1+
ARG DJANGO_CONTAINER_VERSION=1.4.1
22

33
FROM gcr.io/uwit-mci-axdd/django-container:${DJANGO_CONTAINER_VERSION} as app-container
44

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ services:
1111
- "${PORT:-8000}:8000"
1212
environment:
1313
ENV: localdev
14-
AUTH_MODULE: ${AUTH_MODULE:-all_ok}
14+
SPOTSEEKER_OAUTH_ENABLED: ${SPOTSEEKER_OAUTH_ENABLED}
1515
SPOTSEEKER_AUTH_ADMINS: ${SPOTSEEKER_AUTH_ADMINS}
1616
SPOTSEEKER_WEB_SERVER_HOST: ${SPOTSEEKER_WEB_SERVER_HOST}
1717
SPOTSEEKER_WEB_OAUTH_KEY: ${SPOTSEEKER_WEB_OAUTH_KEY}

docker/app_start.sh

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#!/bin/bash
22

3-
if [ "$ENV" = "localdev" ]
4-
then
3+
if [ "$ENV" = "localdev" ]; then
54

6-
python manage.py migrate
7-
python manage.py loaddata uw.json
8-
python manage.py loaddata dummy_oauth.json
5+
python manage.py migrate
6+
python manage.py loaddata uw.json
97

108
fi

docker/dev-values.yml

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
autoscaling:
2+
enabled: false
3+
minReplicas: 1
4+
maxReplicas: 1
5+
ingress:
6+
enabled: true
7+
tls:
8+
spotseeker:
9+
secretName: dev.api.scout.uw.edu-ingress-cert
10+
hosts:
11+
- dev.api.scout.uw.edu
12+
hosts:
13+
spotseeker:
14+
host: dev.api.scout.uw.edu
15+
paths:
16+
- "/"
17+
annotations:
18+
cert-manager.io/cluster-issuer: letsencrypt
19+
nginx.ingress.kubernetes.io/client-body-buffer-size: "16K"
20+
nginx.ingress.kubernetes.io/proxy-body-size: "20m"
21+
nginx.ingress.kubernetes.io/proxy-read-timeout: "500"
22+
nginx.ingress.kubernetes.io/ssl-ciphers: "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256"
23+
lifecycle:
24+
enabled: true
25+
preStop:
26+
enabled: true
27+
affinity:
28+
podsSpanNodes: true
29+
readiness:
30+
enabled: true
31+
securityPolicy:
32+
enabled: true
33+
externalService:
34+
enabled: true
35+
name: spotseeker-dev-db-service
36+
type: ClusterIP
37+
serviceAddress: 172.18.0.196
38+
servicePort: 3306
39+
database:
40+
engine: mysql
41+
name: api_dev
42+
hostname: spotseeker-dev-db-service
43+
secretName: dev.api.scout.uw.edu-sql-secrets
44+
repo: spotseeker
45+
instance: dev
46+
image:
47+
repository: gcr.io/uwit-mci-axdd/spotseeker
48+
tag: IMAGE_TAG
49+
memcached:
50+
enabled: true
51+
replicaCount: 1
52+
updateStrategy:
53+
type: RollingUpdate
54+
gcsCredentials:
55+
mounted: true
56+
secretName: dev.api.scout.uw.edu-gc-service-credentials
57+
cronjob:
58+
enabled: false
59+
jobs:
60+
- name: sync-techloan
61+
schedule: "0,15,30,45 * * * *"
62+
command: ["/scripts/management_command.sh"]
63+
args: ["sync_techloan"]
64+
daemon:
65+
enabled: false # cronjob is probably more appropriate
66+
daemons:
67+
- name: sync-techloan
68+
replicaCount: 1
69+
command: ["/scripts/management_daemon.sh"]
70+
args: ["--delay", "300", "sync_techloan"]
71+
environmentVariables:
72+
- name: AUTH_MODULE
73+
value: oauth
74+
- name: CLUSTER_CNAME
75+
value: dev.api.scout.uw.edu
76+
- name: ENV
77+
value: dev
78+
- name: WEBSERVER
79+
value: nginx
80+
- name: CACHE_MAX_ENTRIES
81+
value: "1000"
82+
- name: CACHE_TIMEOUT
83+
value: "86400"
84+
externalSecrets:
85+
enabled: true
86+
secrets:
87+
- name: dev.api.scout.uw.edu-secrets
88+
externalKey: axdd/kv/data/scout/dev-api/secrets
89+
data:
90+
- name: django-secret
91+
property: django-secret
92+
- name: spotseeker-auth-admins
93+
property: spotseeker-auth-admins
94+
- name: storage-bucket-name
95+
property: storage-bucket-name
96+
- name: storage-project-id
97+
property: storage-project-id
98+
- name: spotseeker-techloan-url
99+
property: spotseeker-techloan-url
100+
- name: spotseeker-web-server-host
101+
property: spotseeker-web-server-host
102+
- name: spotseeker-web-oauth-key
103+
property: spotseeker-web-oauth-key
104+
- name: spotseeker-web-oauth-secret
105+
property: spotseeker-web-oauth-secret
106+
- name: spotseeker-web-oauth-user
107+
property: spotseeker-web-oauth-user
108+
- name: dev.api.scout.uw.edu-sql-secrets
109+
externalKey: axdd/kv/data/scout/common/sql-secrets
110+
data:
111+
- name: username
112+
property: username
113+
- name: password
114+
property: password
115+
- name: dev.api.scout.uw.edu-gc-service-credentials
116+
externalKey: axdd/kv/data/scout/common/gc-service-credentials
117+
data:
118+
- name: credentials.json
119+
property: credentials.json
120+
environmentVariablesSecrets:
121+
djangoSecret:
122+
name: DJANGO_SECRET
123+
secretName: dev.api.scout.uw.edu-secrets
124+
secretKey: django-secret
125+
spotseekerAuthAdmins:
126+
name: SPOTSEEKER_AUTH_ADMINS
127+
secretName: dev.api.scout.uw.edu-secrets
128+
secretKey: spotseeker-auth-admins
129+
storageBucketName:
130+
name: STORAGE_BUCKET_NAME
131+
secretName: dev.api.scout.uw.edu-secrets
132+
secretKey: storage-bucket-name
133+
storageProjectId:
134+
name: STORAGE_PROJECT_ID
135+
secretName: dev.api.scout.uw.edu-secrets
136+
secretKey: storage-project-id
137+
spotseekerTechloanUrl:
138+
name: SPOTSEEKER_TECHLOAN_URL
139+
secretName: dev.api.scout.uw.edu-secrets
140+
secretKey: spotseeker-techloan-url
141+
spotseekerWebServerHost:
142+
name: SPOTSEEKER_WEB_SERVER_HOST
143+
secretName: dev.api.scout.uw.edu-secrets
144+
secretKey: spotseeker-web-server-host
145+
spotseekerWebOauthKey:
146+
name: SPOTSEEKER_WEB_OAUTH_KEY
147+
secretName: dev.api.scout.uw.edu-secrets
148+
secretKey: spotseeker-web-oauth-key
149+
spotseekerWebOauthSecret:
150+
name: SPOTSEEKER_WEB_OAUTH_SECRET
151+
secretName: dev.api.scout.uw.edu-secrets
152+
secretKey: spotseeker-web-oauth-secret
153+
spotseekerWebOauthUser:
154+
name: SPOTSEEKER_WEB_OAUTH_USER
155+
secretName: dev.api.scout.uw.edu-secrets
156+
secretKey: spotseeker-web-oauth-user

docker/prod-values.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ daemon:
7171
command: ["/scripts/management_daemon.sh"]
7272
args: ["--delay", "300", "sync_techloan"]
7373
environmentVariables:
74-
- name: AUTH_MODULE
75-
value: oauth
74+
- name: SPOTSEEKER_OAUTH_ENABLED
75+
value: true
7676
- name: CLUSTER_CNAME
7777
value: api.scout.uw.edu
7878
- name: ENV

docker/settings.py

+32-8
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,36 @@
88
DEBUG = False
99

1010
INSTALLED_APPS += [
11-
"oauth_provider",
1211
"spotseeker_server",
12+
"oauth2_provider",
13+
"corsheaders",
1314
"django_extensions",
1415
]
1516

1617
MIDDLEWARE += [
1718
"spotseeker_server.logger.oauth.LogMiddleware",
19+
"corsheaders.middleware.CorsMiddleware",
1820
]
1921

22+
AUTH_USER_MODEL = "spotseeker_server.Client"
23+
24+
AUTHENTICATION_BACKENDS = (
25+
"oauth2_provider.backends.OAuth2Backend",
26+
"django.contrib.auth.backends.ModelBackend",
27+
)
28+
29+
CORS_ORIGIN_ALLOW_ALL = DEBUG
30+
if os.getenv("ENV", "localdev") == "prod":
31+
CORS_ALLOWED_ORIGINS = [
32+
"https://scout.uw.edu",
33+
"https://manager.scout.uw.edu",
34+
]
35+
else:
36+
CORS_ALLOWED_ORIGINS = [
37+
"https://test.scout.uw.edu",
38+
"https://test.manager.scout.uw.edu",
39+
]
40+
2041
# django storages settings
2142
if not DEBUG:
2243
DEFAULT_FILE_STORAGE = "storages.backends.gcloud.GoogleCloudStorage"
@@ -28,9 +49,11 @@
2849
"/gcs/credentials.json"
2950
)
3051

31-
SPOTSEEKER_AUTH_MODULE = "spotseeker_server.auth.{}".format(
32-
os.getenv("AUTH_MODULE", "all_ok")
33-
)
52+
SPOTSEEKER_OAUTH_ENABLED = os.getenv("SPOTSEEKER_OAUTH_ENABLED", not DEBUG)
53+
# convert string to boolean if set in .env
54+
if type(SPOTSEEKER_OAUTH_ENABLED) == str:
55+
SPOTSEEKER_OAUTH_ENABLED = SPOTSEEKER_OAUTH_ENABLED.lower() == "true"
56+
3457
# turn string of auth admins into list
3558
SPOTSEEKER_AUTH_ADMINS = (
3659
os.getenv("SPOTSEEKER_AUTH_ADMINS", "").replace(" ", "").split(",")
@@ -60,10 +83,11 @@
6083
}
6184
}
6285
else:
63-
# The various MEMCACHED variables are set in django-container's base_settings/common.py
86+
# The various MEMCACHED variables are set in django-container's
87+
# base_settings/common.py
6488
CACHES = {
65-
'default': {
66-
'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache',
67-
'LOCATION': MEMCACHED_SERVERS,
89+
"default": {
90+
"BACKEND": "django.core.cache.backends.memcached.PyLibMCCache",
91+
"LOCATION": MEMCACHED_SERVERS,
6892
}
6993
}

docker/test-values.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ daemon:
6565
command: ["/scripts/management_daemon.sh"]
6666
args: ["--delay", "300", "sync_techloan"]
6767
environmentVariables:
68-
- name: AUTH_MODULE
69-
value: oauth
68+
- name: SPOTSEEKER_OAUTH_ENABLED
69+
value: "true"
7070
- name: CLUSTER_CNAME
7171
value: test.api.scout.uw.edu
7272
- name: ENV

docker/urls.py

+12-22
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,24 @@
1-
"""docker URL Configuration
1+
# Copyright 2024 UW-IT, University of Washington
2+
# SPDX-License-Identifier: Apache-2.0
23

3-
The `urlpatterns` list routes URLs to views. For more information please see:
4-
https://docs.djangoproject.com/en/1.11/topics/http/urls/
5-
Examples:
6-
Function views
7-
1. Add an import: from my_app import views
8-
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
9-
Class-based views
10-
1. Add an import: from other_app.views import Home
11-
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
12-
Including another URLconf
13-
1. Import the include() function: from django.conf.urls import url, include
14-
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
15-
"""
4+
from .base_urls import *
165
from django.conf import settings
17-
from django.conf.urls import url, include
6+
from django.urls import path, include
7+
from django.contrib import admin
188

19-
urlpatterns = [
20-
url(r'^auth/', include('oauth_provider.urls')),
21-
url(r'^api/', include('spotseeker_server.urls')),
22-
url(r'^', include('django_prometheus.urls')), # add here for django 1.11 compatibility
9+
urlpatterns += [
10+
path("api/", include("spotseeker_server.urls")),
11+
path(
12+
"auth/", include("oauth2_provider.urls", namespace="oauth2_provider")
13+
),
2314
]
2415

2516
if settings.DEBUG:
26-
from django.contrib import admin
2717
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
2818

2919
urlpatterns += [
30-
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
31-
url(r'^admin/', include(admin.site.urls)),
20+
path("admin/doc/", include("django.contrib.admindocs.urls")),
21+
path("admin/", admin.site.urls),
3222
]
3323

3424
urlpatterns += staticfiles_urlpatterns()

requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# these two can be upgraded when django gets an update
22
mysqlclient~=1.3
3-
django-prometheus~=2.0
3+
# this is temporary for testing migrations in upgrade
4+
django-extensions==2.2.*
45
-e .

sample.env

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
# Port to connect to with your browser
44
#PORT=8001
55

6-
# Whether to use all_ok (default) or oauth auth module
7-
#AUTH_MODULE=oauth
8-
96
# Comma separated list of admins
107
#SPOTSEEKER_AUTH_ADMINS=javerage,demo_user
118

9+
# enabled oauth (True or False)
10+
#SPOTSEEKER_OAUTH_ENABLED=True
11+
1212
# URL to sync techloan from sync_techloan management command
13-
#SPOTSEEKER_TECHLOAN_URL=https://EXAMPLE_DOMAIN/techloan/api/v2/type/?embed=availability&embed=class
13+
#SPOTSEEKER_TECHLOAN_URL=https://EXAMPLE_DOMAIN/techloan/api/v2/type/?embed=availability&embed=class
14+
15+
#ENV=localdev

setup.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@
77
version="1.0",
88
description="REST Backend for SpaceScout",
99
install_requires=[
10-
"Django==1.11.*",
10+
"Django==2.2.*",
1111
"future",
1212
"mock<=1.0.1",
1313
"oauthlib==3.1.*",
14+
"django-oauth-toolkit",
15+
"django-cors-headers==3.10.*",
1416
"requests==2.26.*",
1517
"requests-oauthlib==1.3.*",
1618
"Pillow",
1719
"pylibmc", # switch to what django-container uses upon upgrade
1820
"pyproj",
1921
"pytz",
2022
"simplejson>=2.1",
21-
"django-oauth-plus@git+https://github.com/edx-unsupported/django-oauth-plus#egg=2.2.9.edx-4",
23+
# "django-oauth-plus@git+https://github.com/abztrakt/django-oauth-plus@spotseeker-changes#egg=2.2.9.edx-4",
2224
"django-storages[google]",
2325
"schema",
2426
"six",

spotseeker_server/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 UW-IT, University of Washington
1+
# Copyright 2024 UW-IT, University of Washington
22
# SPDX-License-Identifier: Apache-2.0
33

44
__version__ = "1.0"

0 commit comments

Comments
 (0)