|
1 | | -CSH Web Packet |
2 | | -============== |
| 1 | +# CSH Web Packet |
3 | 2 |
|
4 | 3 | [](https://www.python.org/downloads/release/python-360/) |
5 | 4 | [](https://travis-ci.org/ComputerScienceHouse/packet) |
6 | 5 |
|
7 | | -Web Packet is used by CSH to facilitate the evaluations of our members and keep track of packet signatures on the web |
| 6 | +Packet is used by CSH to facilitate the freshmen packet portion of our introductory member evaluation process. This is |
| 7 | +the second major iteration of packet on the web. The first version was |
| 8 | +[Tal packet](https://github.com/TalCohen/CSHWebPacket). |
8 | 9 |
|
9 | | -Authorization |
10 | | -------------- |
| 10 | +## Setup |
| 11 | +**Requires Python 3.6 or newer.** |
11 | 12 |
|
12 | | -Authentication happens via pyOIDC with CSH SSO, authenticating as the user who is viewing the page. |
13 | | -We have two different realms, and the site changes depending which realm is in use. |
| 13 | +To get the server working you'll just need the Python dependencies and some secrets. There will be some UI issues due |
| 14 | +to missing assets though. To solve that you'll want to set up the front end dependencies or download a copy of the |
| 15 | +current assets from prod. |
14 | 16 |
|
15 | | -The server uses heavy caching via lru_cache to speed up the results as much as possible |
| 17 | +Alternatively, you can set up a Docker container using `Dockerfile`. This is what's used in prod so it's the most |
| 18 | +reliable method. |
16 | 19 |
|
17 | | -Setup |
18 | | ------- |
| 20 | +### Python dependencies |
| 21 | +Use `pip3 install -r requirements.txt` to install the required python dependencies. A |
| 22 | +[venv](https://packaging.python.org/tutorials/installing-packages/#creating-virtual-environments) is *highly* |
| 23 | +recommended. |
19 | 24 |
|
20 | | -For local development setup follow these steps: |
| 25 | +If 1 or more of the packages fail to install the likely issue is missing header files for the libraries with native C |
| 26 | +components. See the contents of `Dockerfile` for the Linux packages that you'll need. On windows it's a bit more of a |
| 27 | +pain. Try using [WSL](https://docs.microsoft.com/en-us/windows/wsl/about) or finding a pre-compiled wheel from a |
| 28 | +trustworthy source. |
21 | 29 |
|
22 | | -1. ```pip install -r requirements.txt``` |
23 | | -2. `Create config.py` or set environment variables |
24 | | - - Several of these variables require keys and information, please reach out to an RTP for testing information |
25 | | -3. Run `wsgi.py` |
| 30 | +### Frontend dependencies |
| 31 | +To build any of the frontend dependencies you're going to need [node](https://nodejs.org/), |
| 32 | +[npm](https://www.npmjs.com/get-npm), and [yarn](https://yarnpkg.com/). |
26 | 33 |
|
| 34 | +Make sure your system is also capable of building with [Sass](https://sass-lang.com/). To download all node |
| 35 | +dependencies run. |
| 36 | +```bash |
| 37 | +yarn install |
| 38 | +``` |
| 39 | + |
| 40 | +Following the install, you should be able to run `gulp` |
| 41 | +```bash |
| 42 | +gulp production |
| 43 | +``` |
| 44 | + |
| 45 | +If it doesn't work for some reason, you may have to globally install gulp through npm |
| 46 | +```bash |
| 47 | +npm install -g gulp |
| 48 | +``` |
| 49 | + |
| 50 | +### Secrets and configuration |
| 51 | +Packet supports 2 primary configuration methods: |
| 52 | +1. Environment variables - See `config.env.py` for the expected names and default values. |
| 53 | +2. Pyfile config - Create a `config.py` file in the root directory of the project and set variables to override the |
| 54 | +values in `config.env.py`. |
| 55 | + |
| 56 | +Both methods can be used at the same time, though Pyfile config will take priority over environment variables. |
| 57 | + |
| 58 | +**Required configuration values:** |
| 59 | +* `SQLALCHEMY_DATABASE_URI` - Must be set to a valid [SQLAlchemy DB URI](http://flask-sqlalchemy.pocoo.org/2.3/config/#connection-uri-format). |
| 60 | +A dev database for the project is hosted by CSH. Contact a current maintainer of packet for the details. |
| 61 | +* `LDAP_BIND_DN` - Must point to a valid CSH account on LDAP. Use the form |
| 62 | +`uid={username},cn=users,cn=accounts,dc=csh,dc=rit,dc=edu`. |
| 63 | +* `LDAP_BIND_PASS` - The password for that CSH account. |
| 64 | +* `SECRET_KEY` - Use a sufficiently long random string here. The `flask create-secret` command can generate a good one |
| 65 | +for you. |
| 66 | +* `OIDC_CLIENT_SECRET` - Required to use CSH auth. Contact a current maintainer of packet for the details. |
27 | 67 |
|
28 | | -Commands |
29 | | --------- |
| 68 | +To switch between OIDC realms you'll need to set the modify the following values: |
| 69 | +* `OIDC_CLIENT_SECRET` - Unique to each realm. Again, contact a current maintainer of packet for the details. |
| 70 | +* `OIDC_ISSUER` - The OIDC issuer URL. |
| 71 | +* `REALM` - Set to `"csh"` or `"intro"` depending on the realm you want. |
30 | 72 |
|
31 | | -The flask CLI provides all the methods needed to setup a packet and a packet season |
| 73 | +By default `OIDC_ISSUER` and `REALM` are configured for the CSH members realm. |
32 | 74 |
|
| 75 | +## Usage |
| 76 | +To run packet using the flask dev server use this command: |
| 77 | +```bash |
| 78 | +python3 wsgi.py |
33 | 79 | ``` |
34 | | - create-packets Creates a new packet season for each of the freshmen in the given CSV. |
35 | | - create-secret Generates a securely random token. |
36 | | - db Perform database migrations. |
37 | | - ldap-sync Updates the upper and misc sigs in the DB to match ldap. |
38 | | - sync-freshmen Updates the freshmen entries in the DB to match the given CSV. |
39 | | - fetch-results Fetches and prints the results from a given packet season. |
| 80 | +The Flask debug mode flag can be set using via the config system explained above. |
| 81 | + |
| 82 | +Alternative you can run it through [gunicorn](https://gunicorn.org/) using this command: |
| 83 | +```bash |
| 84 | +gunicorn -b :8000 packet:app --access-logfile - |
| 85 | +``` |
| 86 | + |
| 87 | +### CLI |
| 88 | +Packet makes use of the Flask CLI for exposing functionality to devs and admins. This is primarily designed to be used |
| 89 | +locally with the target DB set via the server's config values. |
| 90 | + |
| 91 | +To use the CLI just set the project up as normal and then run the `flask` command in the project's root directory. |
| 92 | +It'll automatically load up the app and show you a list of available commands. For more details on a particular command |
| 93 | +use the help flag like this: |
| 94 | +```bash |
| 95 | +flask {command} --help |
40 | 96 | ``` |
41 | 97 |
|
42 | | -Code Standards |
43 | | ------------- |
| 98 | +**WARNING:** Be sure to double check which DB you're pointed at when using one of the admin or DB commands. |
44 | 99 |
|
45 | | -Use Pylint to ensure your code follows standards. Commits will be pylinted by Travis CI, if your |
46 | | -build fails you must fix whatever it tells you is wrong before it will be merged. |
| 100 | +All DB commands are from the `Flask-Migrate` library and are used to configure DB migrations through Alembic. See their |
| 101 | +docs [here](https://flask-migrate.readthedocs.io/en/latest/) for details. |
| 102 | + |
| 103 | +## Code standards |
| 104 | +This project is configured to use Pylint. Commits will be pylinted by Travis CI and if the score drops your build will |
| 105 | +fail blocking you from merging. To make your life easier just run it before making a PR. |
| 106 | + |
| 107 | +To run pylint use this command: |
| 108 | +```bash |
| 109 | +pylint packet |
| 110 | +``` |
47 | 111 |
|
48 | | -To check locally, run ```pylint packet``` |
| 112 | +All python files should have a top-level docstring explaining the contents of the file and complex functions should |
| 113 | +have docstrings explaining any non-obvious portions. |
0 commit comments