Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Https server #2

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
default_language_version:
python: python3.8
python: python3.9
repos:
- repo: https://github.com/psf/black
rev: 20.8b1 # not a "beta"; just weird versioniong
rev: 22.3.0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have been switching to the local repo config method for pre-commit. Instead of having to specify a version and repo url for black and flake it just uses whatever you currently have installed in the virtualenv. It's soooo much easier and I cannot understand why it isn't the default. AFAICT there's no downside.

See my recent PR for the porta package updates for an example.

hooks:
- id: black
args:
# don't actually format, just exit with 0 (no changes) or 1 (changes needed)
- --check
- casdemoserver
- hkey
- repo: https://gitlab.com/pycqa/flake8
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to get changed to pull from github. the gitlab url makes me authenticate and is a known "bug". https://www.reddit.com/r/Python/comments/yvfww8/flake8_took_down_the_gitlab_repository_in_favor/

rev: 3.7.9
hooks:
Expand Down
16 changes: 12 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ENV PYTHONUNBUFFERED 1
# update the base OS packages
RUN apk update \
&& apk upgrade \
&& apk add --no-cache bash \
&& apk add --no-cache --update sqlite

RUN mkdir /app
Expand All @@ -20,8 +21,15 @@ RUN pip install --no-cache-dir -U pip pip-tools \
ADD . /app

WORKDIR /app
RUN python manage.py makemigrations hkey
RUN python manage.py migrate
RUN demo_data/import.sh

EXPOSE 9000
CMD python manage.py runserver 0.0.0.0:9000
# Load fixture data
RUN python manage.py loaddata fixtures/auth_group.json
RUN python manage.py loaddata fixtures/hkey_grouper.json
RUN python manage.py loaddata fixtures/hkey_huser.json
RUN python manage.py loaddata fixtures/hkey_memberof.json
# RUN demo_data/import.sh

# HTTPS version
EXPOSE 9001
CMD python manage.py runsslserver 0.0.0.0:9001
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can expose more than one port but you can't have multiple CMD directives. This would need to be done with a runtime env var or something. Do we actually still need to support both? If not I would simply remove the non-ssl port 9000 version. The image this project produces is only ever used for local dev. We'd just need to make sure the docker compose configs for porta/porta-auto get updated to use https in the CAS_SERVER_URL setting.

29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,54 @@ pre-commit install
## Run locally using docker

```bash
docker build -t demo-cas-server .
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example image tag really should be hdce/hkey-demo-cas-server so that the image gets the name used in the porta/porta-auto/doki docker compose configs

docker-compose up
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no docker compose config here so not sure where this came from

```

## Run locally the old way
## Run locally

```
python manage.py migrate
./demo_data/import.sh
# HTTP
python manage.py runserver 9000

# HTTPS
python manage.py runsslserver 127.0.0.1:9001 &
```

## Default user/passwd combos

| username | password |
| -------- | -------- |
| admin | testinstructor |
| admin | rivendel |
| dr_fauci | testinstructor
| producer | |
| nancy | |
| joe | teststudent |
| dokiadmin| okaydoki |
| dokistaff| okaydoki |
| dokiuser | okaydoki |

(dr_fauci has 2 courses)



## Test

Open `http://127.0.0.1:9000/cas/login`

---
or

Open `https://127.0.0.1:9001/cas/login`

## To use the https service as a demo cas server (in porta or doki)

Add these settings to .env or to <project>/settings.py

# Point to the service using https
CAS_SERVER_URL=https://localhost:9001/cas/

# Turn off ssl VERIFICATION to use self signed certs
CAS_VERIFY_SSL_CERTIFICATE=False

1 change: 1 addition & 0 deletions casdemoserver/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"django.contrib.staticfiles",
"hkey",
"mama_cas",
"sslserver",
]

MIDDLEWARE = [
Expand Down
4 changes: 3 additions & 1 deletion casdemoserver/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
from django.conf.urls import include
from django.conf.urls import url
from django.urls import path
from django.contrib import admin

from . import views

urlpatterns = [
path("", views.index, name="index"),
path("ping", views.ping, name="ping"),
# path('admin/', admin.site.urls),
path("admin/", admin.site.urls),
url(r"^cas/", include("mama_cas.urls")),
]
7 changes: 7 additions & 0 deletions demo_data/hkey_grouper.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
5,harvard:org:schools:dce:apps:opencast:role-huid-hkl-users-opencast
6,harvard:ref:courses:ext:2013:winter:329878-enrollees
7,harvard:ref:courses:ext:2013:spring:328484-enrollees
8,harvard:ref:courses:ext:2013:spring:328479-enrollees
Expand Down Expand Up @@ -37,3 +38,9 @@
44,harvard:ref:courses:ext:2019:spring:539709-staff
46,harvard:ref:courses:ext:2019:fall:540378-staff
47,harvard:ref:courses:ext:2019:fall:540378-enrollees
48,harvard:org:schools:dce:apps:porta:role-admin-users-porta
49,harvard:org:schools:dce:apps:porta:role-support-users-porta
50,harvard:ref:courses:ext:2021:fall:589764-staff
51,harvard:org:schools:dce:apps:doki:role-admin-doki
52,harvard:org:schools:dce:apps:doki:role-staff-doki
53,harvard:org:schools:dce:apps:doki:role-user-doki
6 changes: 5 additions & 1 deletion demo_data/hkey_huser.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
2,pbkdf2_sha256$100000$vpLqcspQX5JY$FkmPtG7d7AbKZRwXwEwnIr5MF7Ti5Nh2bdavIqRTBFk=,"2020-07-20 21:49:03.312501",0,nancy,nancy,gray,[email protected],0,1,"2020-06-15 19:00:13",123456789,123456789
3,pbkdf2_sha256$100000$BBlXz2KTGLEl$QW5HJcJ71LXJl/LCrljS2qLYeYPCfuc3irdZBh/dBX8=,"2021-04-12 17:35:51.676268",0,joe,Joe,Blow,[email protected],0,1,"2020-06-15 19:11:06",123xid567,
4,pbkdf2_sha256$100000$0vnPFeuunzAP$EjQYw+mJtM2xiDZmaY2ify3XLwbiHmEFl1UGeM23VTs=,"2021-04-12 17:35:09.763324",0,dr_fauci,Anthony,Fauci,[email protected],0,1,"2020-06-17 23:16:43",7778889999,7778889999
5,pbkdf2_sha256$100000$tfuAvIbn11g5$ndX/mlBaoelMOtY/pTIyE4I9sxqtwS/j1DiWpt2zux0=,"2020-07-31 20:52:20.446621",0,producer,The,Producer,[email protected],1,1,"2020-07-17 16:19:58",1234556,1234556
5,pbkdf2_sha256$100000$tfuAvIbn11g5$ndX/mlBaoelMOtY/pTIyE4I9sxqtwS/j1DiWpt2zux0=,"2020-07-31 20:52:20.446621",0,producer,The,Producer,[email protected],1,1,"2020-07-17 16:19:58",12345567,12345567
6,pbkdf2_sha256$100000$IIBHRthVIi5O$tAfAxWwhldheReyIqA6XR64vbUvwJULQfh68gG8SRAI=,"2020-07-28 21:22:35.093330",0,dr_birx,Deborah,Birx,[email protected],0,1,"2020-07-24 22:40:19",66613369,66613369
7,pbkdf2_sha256$150000$gokOBrztYYha$Cbefreo0TC13zKWNXRRPWYwKuLfPK+q3F5O+1t3T0QQ=,"2023-02-27 21:24:21.665202",0,support,Tech,Support,,0,1,"2022-10-14 19:48:05",11223344,11223344
8,pbkdf2_sha256$150000$1RhoRzwzI1Jd$M7UXl93tY1vk5ryey7LOcAFnTgbeQ2LFaQXp/UEAAEM=,,0,dokiadmin,Admin,Doki,,0,1,2023-11-14 23:09:33,56785678,56785678
9,pbkdf2_sha256$150000$RNU2zu9sY5Zb$wzXdehfW1cmeJETo5bcXvRC3tm644yEF/9CZXR25jjA=,,0,dokistaff,Producer,Doki,,0,1,2023-11-14 23:12:16,567891234,567891234
10,pbkdf2_sha256$150000$TnW5Niqjb931$WdmLN/G1jocJ1nE5olNZ6sm6/Ze7DcncSbfwSftqJ/o=,,0,dokiworker,Worker,Doki,,0,1,2023-11-14 23:13:02,567891233,567891233
4 changes: 2 additions & 2 deletions demo_data/hkey_huser_groups.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
4,1,3
5,5,3
4,1,1
5,5,1
7 changes: 7 additions & 0 deletions demo_data/hkey_memberof.csv
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@
20,35,5
21,35,1
22,46,4
23,48,5
25,50,4
26,49,7
27,50,4
28,51,8
29,52,9
30,53,10
3 changes: 2 additions & 1 deletion demo_data/import.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh

SCRIPTDIR=$(dirname $(readlink -f $0))
#SCRIPTDIR=$(dirname $(readlink -f $0))
SCRIPTDIR=./demo_data
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the point of the command to figure out the $SCRIPTDIR was so that it didn't matter what your cwd was when running the script. Was it not working?


for f in ${SCRIPTDIR}/*.csv; do
tablename=$(basename $f .csv)
Expand Down
20 changes: 20 additions & 0 deletions fixtures/auth_group.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"model": "auth.group",
"pk": 1,
"fields": {
"name": "harvard:ref:courses:ext:2021:fall:589764-staff",
"permissions": []
}
},
{
"model": "auth.group",
"pk": 2,
"fields": {
"name": "ChangeGrouper",
"permissions": [
26
]
}
}
]
Loading