Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ If it doesn't work for some reason, you may have to globally install gulp throug
npm install -g gulp
```

### Local Development
* PostgreSQL
You'll need a postgres instance to use as a development DB.
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.
To get setup using docker, run
```bash
docker run --name packet-postgres -e POSTGRES_PASSWORD=mysecretpassword -d -p 5432:5432 postgres
Copy link
Member

Choose a reason for hiding this comment

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

Any reason to not just toss this into a docker-compose file, like I did for self-service?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I use podman, so docker-compose is not something I default to yet.

```
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`.
Once the container is up, run the following to set up the database tables.
```bash
flask db upgrade
Copy link
Member

Choose a reason for hiding this comment

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

We should really get in the habit of having the application itself run migrations automatically when it starts. I'm not sure there is any reason not to.

```

### Secrets and configuration
Packet supports 2 primary configuration methods:
1. Environment variables - See `config.env.py` for the expected names and default values.
Expand Down
17 changes: 15 additions & 2 deletions config.env.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
See the readme for more information
"""
from distutils.util import strtobool
from os import environ
from os import environ, path, getcwd

# Flask config
DEBUG = False
Expand All @@ -25,12 +25,25 @@
OIDC_CLIENT_SECRET = environ.get("PACKET_OIDC_CLIENT_SECRET", "PLEASE_REPLACE_ME")

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

# LDAP config
LDAP_BIND_DN = environ.get("PACKET_LDAP_BIND_DN", None)
LDAP_BIND_PASS = environ.get("PACKET_LDAP_BIND_PASS", None)
LDAP_MOCK_MEMBERS = [
{'uid':'evals', 'groups': ['eboard', 'eboard-evaluations', 'active']},
{'uid':'imps-3da', 'groups': ['eboard', 'eboard-imps', '3da', 'active']},
{
'uid':'rtp-cm-webs-onfloor',
'groups': ['active-rtp', 'rtp', 'constitutional_maintainers', 'webmaster', 'active', 'onfloor'],
'room_number': 1024
},
{'uid':'misc-rtp', 'groups': ['rtp']},
{'uid':'onfloor', 'groups': ['active', 'onfloor'], 'room_number': 1024},
{'uid':'active-offfloor', 'groups': ['active']},
{'uid':'alum', 'groups': ['member']},
]

# Mail Config
MAIL_PROD = strtobool(environ.get("PACKET_MAIL_PROD", "False"))
Expand Down
34 changes: 23 additions & 11 deletions packet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,41 @@
app.config['OIDC_CLIENT_SECRET']))

# Initialize Onesignal Notification apps
csh_onesignal_client = onesignal.Client(user_auth_key=app.config['ONESIGNAL_USER_AUTH_KEY'],
app_auth_key=app.config['ONESIGNAL_CSH_APP_AUTH_KEY'],
app_id=app.config['ONESIGNAL_CSH_APP_ID'])

intro_onesignal_client = onesignal.Client(user_auth_key=app.config['ONESIGNAL_USER_AUTH_KEY'],
app_auth_key=app.config['ONESIGNAL_INTRO_APP_AUTH_KEY'],
app_id=app.config['ONESIGNAL_INTRO_APP_ID'])
csh_onesignal_client = None
if app.config['ONESIGNAL_USER_AUTH_KEY'] and \
app.config['ONESIGNAL_CSH_APP_AUTH_KEY'] and \
app.config['ONESIGNAL_CSH_APP_ID']:
csh_onesignal_client = onesignal.Client(
user_auth_key=app.config['ONESIGNAL_USER_AUTH_KEY'],
app_auth_key=app.config['ONESIGNAL_CSH_APP_AUTH_KEY'],
app_id=app.config['ONESIGNAL_CSH_APP_ID']
)
app.logger.info('CSH Onesignal configured and notifications enabled')

intro_onesignal_client = None
if app.config['ONESIGNAL_USER_AUTH_KEY'] and \
app.config['ONESIGNAL_INTRO_APP_AUTH_KEY'] and \
app.config['ONESIGNAL_INTRO_APP_ID']:
intro_onesignal_client = onesignal.Client(
user_auth_key=app.config['ONESIGNAL_USER_AUTH_KEY'],
app_auth_key=app.config['ONESIGNAL_INTRO_APP_AUTH_KEY'],
app_id=app.config['ONESIGNAL_INTRO_APP_ID']
)
app.logger.info('Intro Onesignal configured and notifications enabled')

# OIDC Auth
auth = OIDCAuthentication({'app': APP_CONFIG}, app)

# LDAP
_ldap = csh_ldap.CSHLDAP(app.config['LDAP_BIND_DN'], app.config['LDAP_BIND_PASS'])
app.logger.info('OIDCAuth configured')

# Sentry
sentry_sdk.init(
dsn=app.config['SENTRY_DSN'],
integrations=[FlaskIntegration(), SqlalchemyIntegration()]
)

app.logger.info('OIDCAuth and LDAP configured')

# pylint: disable=wrong-import-position
from .ldap import ldap
from . import models
from . import context_processors
from . import commands
Expand Down
5 changes: 2 additions & 3 deletions packet/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
from functools import lru_cache
from datetime import datetime

from packet.ldap import ldap_get_member
from packet.models import Freshman
from packet import app
from packet import app, ldap


# pylint: disable=bare-except
@lru_cache(maxsize=128)
def get_csh_name(username):
try:
member = ldap_get_member(username)
member = ldap.get_member(username)
return member.cn + ' (' + member.uid + ')'
except:
return username
Expand Down
Loading