Skip to content
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,5 @@ dmypy.json
.pyre/

# End of https://www.gitignore.io/api/macos,python

.env
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ RUN pip install --no-cache-dir -r requirements.txt

COPY jumpstart jumpstart

EXPOSE 5000
EXPOSE 8080

RUN useradd jumpstart
RUN chown jumpstart /usr/local/jumpstart
RUN mkdir -p /usr/local/var
RUN chown jumpstart:jumpstart /usr/local/var
USER jumpstart

CMD ["gunicorn", "jumpstart:app"]
CMD ["sh", "-c", "gunicorn jumpstart:app --bind=0.0.0.0:8080 --access-logfile - --error-log - --capture-output --timeout=600"]
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,36 @@ See it live [here](https://jumpstart.csh.rit.edu)!
This project uses [Python](http://nodejs.org), [Flask](https://npmjs.com), SQL, HTML/CSS, and Javascript.

1. Clone and cd into the repo: `git clone https://github.com/ComputerScienceHouse/Jumpstart`
2. Run `pip install -r requirements.txt`
2. Run `pip install -r requirements.txt` (or use docker)
3. Ask opcomm for secrets
- The secrets package follows the directory structure:
src/
secrets/
client_secrets.json
4. Run `flask --app jumpstart run`
- Google clients secret json
- Jumpstart API keys (runs without this... not entirely sure what it does)
4. Run `flask --app jumpstart run` (please use docker)
5. Results

Jumpstart expects the following environment variables to be defined:
```
FLASK_APP=jumpstart:App
JUMPSTART_API_KEYS=KEYS
TZ=TIMEZONE
SENTRY_DSN=LINK
GOOGLE_CLIENT_SECERTS_JSON=json from key file
```
## Docker

1. Ensure you are in the project root, then build the image locally with `docker built -t jumpstart .`
2. Run with the following: (Be sure to update env variables)
```
docker run \
-e FLASK_RUN_HOST=0.0.0.0 \
-e FLASK_APP=jumpstart:App \
-e JUMPSTART_API_KEYS=KEYS \
-e TZ=America/New_York \
-e SENTRY_DSN=LINK \
-e GUNICORN_CMD_ARGS="-b=0.0.0.0:5000" \
-v ./secrets:/usr/local/jumpstart/secrets \
-p 5000:5000 \
-p 8080:8080 \
jumpstart
```
```
3. You can also use a `.env` file:
```
docker run \
--env-file='.env'
-p 8080:8080
jumpstart
```
5 changes: 4 additions & 1 deletion jumpstart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from flask_limiter.util import get_remote_address
from flask_httpauth import HTTPTokenAuth
from flask_sqlalchemy import SQLAlchemy
from jumpstart.google import calendar_service
from jumpstart.google import get_calendar_service
from profanityfilter import ProfanityFilter

pf = ProfanityFilter()
Expand All @@ -43,6 +43,9 @@

auth = HTTPTokenAuth(scheme='Token')
api_keys = os.environ.get('JUMPSTART_API_KEYS')
GOOGLE_CLIENT_SECERTS_JSON = os.environ.get('GOOGLE_CLIENT_SECRETS_JSON')

calendar_service = get_calendar_service(GOOGLE_CLIENT_SECERTS_JSON)

tokens = api_keys.split(',') if api_keys else []

Expand Down
12 changes: 8 additions & 4 deletions jumpstart/google.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
import os
import json
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials

SCOPES = ['https://www.googleapis.com/auth/calendar.readonly']

def get_service(api_name, api_version, scopes, key_file_location):
def get_service(api_name, api_version, scopes, key_file_contents):
"""Get a service that communicates to a Google API.

Args:
api_name: The name of the api to connect to.
api_version: The api version to connect to.
scopes: A list auth scopes to authorize for the application.
key_file_location: The path to a valid service account JSON key file.
key_file_contents: The contents of json keyfile.

Returns:
A service that is connected to the specified API.
"""

credentials = ServiceAccountCredentials.from_json_keyfile_name(key_file_location, scopes=scopes)
key_file_json = json.loads(key_file_contents)

credentials = ServiceAccountCredentials.from_json_keyfile_dict(key_file_json, scopes=scopes)

# Build the service object.
service = build(api_name, api_version, credentials=credentials)

return service

# Authenticate and construct service.
calendar_service = get_service(api_name='calendar', api_version='v3', scopes=SCOPES, key_file_location=os.path.join(os.getcwd(), "secrets", "client_secrets.json"))
def get_calendar_service(key_file_contents):
return get_service(api_name='calendar', api_version='v3', scopes=SCOPES, key_file_contents=key_file_contents)