Skip to content

Commit e4d19a7

Browse files
authored
Merge pull request #236 from ComputerScienceHouse/develop
2 parents 5e09efe + 9a706d2 commit e4d19a7

19 files changed

+469
-256
lines changed

.github/dependabot.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "npm" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "weekly"
12+
13+
- package-ecosystem: "pip" # See documentation for possible values
14+
directory: "/" # Location of package manifests
15+
schedule:
16+
interval: "weekly"

.github/workflows/docker-build.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
- master
8+
9+
# Run tests for any PRs.
10+
pull_request:
11+
branches:
12+
- develop
13+
- master
14+
15+
env:
16+
IMAGE_NAME: packet
17+
18+
jobs:
19+
test:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- uses: actions/checkout@v2
24+
25+
- name: Run tests
26+
run: |
27+
if [ -f docker-compose.test.yml ]; then
28+
docker-compose --file docker-compose.test.yml build
29+
docker-compose --file docker-compose.test.yml run sut
30+
else
31+
docker build . --file Dockerfile
32+
fi

.github/workflows/node-js.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Node.js CI
5+
6+
on:
7+
push:
8+
branches: [develop, master]
9+
pull_request:
10+
branches: [develop, master]
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
node-version: [10.x, 12.x, 14.x]
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Use Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v1
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
- run: yarn install
27+
- run: yarn prod

.github/workflows/python-app.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Python application
5+
6+
on:
7+
push:
8+
branches: [master, develop]
9+
pull_request:
10+
branches: [master, develop]
11+
12+
jobs:
13+
lint:
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
python-version: [3.7, 3.8]
19+
20+
steps:
21+
- name: Install ldap dependencies
22+
run: sudo apt-get install libldap2-dev libsasl2-dev
23+
- uses: actions/checkout@v2
24+
- name: Set up Python ${{ matrix.python-version }}
25+
uses: actions/setup-python@v2
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
32+
- name: Lint with pylint
33+
run: |
34+
pylint packet

.travis.yml

-16
This file was deleted.

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM python:3.7-slim-buster
22
MAINTAINER Devin Matte <[email protected]>
33

44
RUN apt-get -yq update && \
5-
apt-get -yq --no-install-recommends install gcc curl libsasl2-dev libldap2-dev libssl-dev && \
5+
apt-get -yq --no-install-recommends install gcc curl libsasl2-dev libldap2-dev libssl-dev gnupg2 && \
66
apt-get -yq clean all
77

88
RUN mkdir /opt/packet

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ If it doesn't work for some reason, you may have to globally install gulp throug
4747
npm install -g gulp
4848
```
4949

50+
### Local Development
51+
* PostgreSQL
52+
You'll need a postgres instance to use as a development DB.
53+
You can use an existing database, like the instance used for the dev branch, use a database on another server, or spin up a container using docker or podman.
54+
To get setup using docker, run
55+
```bash
56+
docker run --name packet-postgres -e POSTGRES_PASSWORD=mysecretpassword -d -p 5432:5432 postgres
57+
```
58+
After the container starts up, you should be able to connect with the connection string `postgresql://postgres:mysecretpassword@localhost:5432/postgres`, which is the default connection string in `config.env.py`.
59+
Once the container is up, run the following to set up the database tables.
60+
```bash
61+
flask db upgrade
62+
```
63+
5064
### Secrets and configuration
5165
Packet supports 2 primary configuration methods:
5266
1. Environment variables - See `config.env.py` for the expected names and default values.

config.env.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
See the readme for more information
44
"""
55
from distutils.util import strtobool
6-
from os import environ
6+
from os import environ, path, getcwd
77

88
# Flask config
99
DEBUG = False
@@ -25,12 +25,25 @@
2525
OIDC_CLIENT_SECRET = environ.get("PACKET_OIDC_CLIENT_SECRET", "PLEASE_REPLACE_ME")
2626

2727
# SQLAlchemy config
28-
SQLALCHEMY_DATABASE_URI = environ.get("PACKET_DATABASE_URI", None)
28+
SQLALCHEMY_DATABASE_URI = environ.get("PACKET_DATABASE_URI", "postgresql://postgres:mysecretpassword@localhost:5432/postgres")
2929
SQLALCHEMY_TRACK_MODIFICATIONS = False
3030

3131
# LDAP config
3232
LDAP_BIND_DN = environ.get("PACKET_LDAP_BIND_DN", None)
3333
LDAP_BIND_PASS = environ.get("PACKET_LDAP_BIND_PASS", None)
34+
LDAP_MOCK_MEMBERS = [
35+
{'uid':'evals', 'groups': ['eboard', 'eboard-evaluations', 'active']},
36+
{'uid':'imps-3da', 'groups': ['eboard', 'eboard-imps', '3da', 'active']},
37+
{
38+
'uid':'rtp-cm-webs-onfloor',
39+
'groups': ['active-rtp', 'rtp', 'constitutional_maintainers', 'webmaster', 'active', 'onfloor'],
40+
'room_number': 1024
41+
},
42+
{'uid':'misc-rtp', 'groups': ['rtp']},
43+
{'uid':'onfloor', 'groups': ['active', 'onfloor'], 'room_number': 1024},
44+
{'uid':'active-offfloor', 'groups': ['active']},
45+
{'uid':'alum', 'groups': ['member']},
46+
]
3447

3548
# Mail Config
3649
MAIL_PROD = strtobool(environ.get("PACKET_MAIL_PROD", "False"))

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"title": "CSH Packet",
33
"name": "csh-packet",
4-
"version": "3.5.1",
4+
"version": "3.5.2",
55
"description": "A web app implementation of the CSH introductory packet.",
66
"bugs": {
77
"url": "https://github.com/ComputerScienceHouse/packet/issues",
@@ -13,6 +13,10 @@
1313
"Joel Eager (https://github.com/JoelEager)",
1414
"Max Meinhold (https://github.com/mxmeinhold)"
1515
],
16+
"scripts": {
17+
"prod": "gulp production",
18+
"lint": "gulp lint"
19+
},
1620
"repository": {
1721
"type": "git",
1822
"url": "https://github.com/ComputerScienceHouse/packet.git"

packet/__init__.py

+23-11
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,41 @@
5050
app.config['OIDC_CLIENT_SECRET']))
5151

5252
# Initialize Onesignal Notification apps
53-
csh_onesignal_client = onesignal.Client(user_auth_key=app.config['ONESIGNAL_USER_AUTH_KEY'],
54-
app_auth_key=app.config['ONESIGNAL_CSH_APP_AUTH_KEY'],
55-
app_id=app.config['ONESIGNAL_CSH_APP_ID'])
56-
57-
intro_onesignal_client = onesignal.Client(user_auth_key=app.config['ONESIGNAL_USER_AUTH_KEY'],
58-
app_auth_key=app.config['ONESIGNAL_INTRO_APP_AUTH_KEY'],
59-
app_id=app.config['ONESIGNAL_INTRO_APP_ID'])
53+
csh_onesignal_client = None
54+
if app.config['ONESIGNAL_USER_AUTH_KEY'] and \
55+
app.config['ONESIGNAL_CSH_APP_AUTH_KEY'] and \
56+
app.config['ONESIGNAL_CSH_APP_ID']:
57+
csh_onesignal_client = onesignal.Client(
58+
user_auth_key=app.config['ONESIGNAL_USER_AUTH_KEY'],
59+
app_auth_key=app.config['ONESIGNAL_CSH_APP_AUTH_KEY'],
60+
app_id=app.config['ONESIGNAL_CSH_APP_ID']
61+
)
62+
app.logger.info('CSH Onesignal configured and notifications enabled')
63+
64+
intro_onesignal_client = None
65+
if app.config['ONESIGNAL_USER_AUTH_KEY'] and \
66+
app.config['ONESIGNAL_INTRO_APP_AUTH_KEY'] and \
67+
app.config['ONESIGNAL_INTRO_APP_ID']:
68+
intro_onesignal_client = onesignal.Client(
69+
user_auth_key=app.config['ONESIGNAL_USER_AUTH_KEY'],
70+
app_auth_key=app.config['ONESIGNAL_INTRO_APP_AUTH_KEY'],
71+
app_id=app.config['ONESIGNAL_INTRO_APP_ID']
72+
)
73+
app.logger.info('Intro Onesignal configured and notifications enabled')
6074

6175
# OIDC Auth
6276
auth = OIDCAuthentication({'app': APP_CONFIG}, app)
63-
64-
# LDAP
65-
_ldap = csh_ldap.CSHLDAP(app.config['LDAP_BIND_DN'], app.config['LDAP_BIND_PASS'])
77+
app.logger.info('OIDCAuth configured')
6678

6779
# Sentry
6880
sentry_sdk.init(
6981
dsn=app.config['SENTRY_DSN'],
7082
integrations=[FlaskIntegration(), SqlalchemyIntegration()]
7183
)
7284

73-
app.logger.info('OIDCAuth and LDAP configured')
7485

7586
# pylint: disable=wrong-import-position
87+
from .ldap import ldap
7688
from . import models
7789
from . import context_processors
7890
from . import commands

packet/context_processors.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
from functools import lru_cache
77
from datetime import datetime
88

9-
from packet.ldap import ldap_get_member
109
from packet.models import Freshman
11-
from packet import app
10+
from packet import app, ldap
1211

1312

1413
# pylint: disable=bare-except
1514
@lru_cache(maxsize=128)
1615
def get_csh_name(username):
1716
try:
18-
member = ldap_get_member(username)
17+
member = ldap.get_member(username)
1918
return member.cn + ' (' + member.uid + ')'
2019
except:
2120
return username

0 commit comments

Comments
 (0)