Skip to content

Commit 528991d

Browse files
committed
well it works...
1 parent 99522a2 commit 528991d

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ RUN pip install --no-cache-dir -r requirements.txt
66

77
COPY jumpstart jumpstart
88

9-
EXPOSE 5000
9+
EXPOSE 8080
1010

1111
RUN useradd jumpstart
1212
RUN chown jumpstart /usr/local/jumpstart
1313
RUN mkdir -p /usr/local/var
1414
RUN chown jumpstart:jumpstart /usr/local/var
1515
USER jumpstart
1616

17-
CMD ["gunicorn", "jumpstart:app"]
17+
# CMD ["gunicorn", "jumpstart:app"]
18+
CMD ["sh", "-c", "gunicorn jumpstart:app --bind=0.0.0.0:8080 --access-logfile - --error-log - --capture-output --timeout=600"]

README.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,29 @@ See it live [here](https://jumpstart.csh.rit.edu)!
99
This project uses [Python](http://nodejs.org), [Flask](https://npmjs.com), SQL, HTML/CSS, and Javascript.
1010

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

2119
Jumpstart expects the following environment variables to be defined:
2220
```
23-
FLASK_APP=jumpstart:App
2421
JUMPSTART_API_KEYS=KEYS
2522
TZ=TIMEZONE
2623
SENTRY_DSN=LINK
24+
GOOGLE_CLIENT_SECERTS_JSON=json from key file
2725
```
2826
## Docker
2927

3028
1. Ensure you are in the project root, then build the image locally with `docker built -t jumpstart .`
3129
2. Run with the following: (Be sure to update env variables)
3230
```
3331
docker run \
34-
-e FLASK_RUN_HOST=0.0.0.0 \
35-
-e FLASK_APP=jumpstart:App \
3632
-e JUMPSTART_API_KEYS=KEYS \
3733
-e TZ=America/New_York \
3834
-e SENTRY_DSN=LINK \
39-
-e GUNICORN_CMD_ARGS="-b=0.0.0.0:5000" \
40-
-v ./secrets:/usr/local/jumpstart/secrets \
41-
-p 5000:5000 \
35+
-p 8080:8080 \
4236
jumpstart
43-
```
37+
```

jumpstart/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from flask_limiter.util import get_remote_address
2828
from flask_httpauth import HTTPTokenAuth
2929
from flask_sqlalchemy import SQLAlchemy
30-
from jumpstart.google import calendar_service
30+
from jumpstart.google import get_calendar_service
3131
from profanityfilter import ProfanityFilter
3232

3333
pf = ProfanityFilter()
@@ -43,6 +43,9 @@
4343

4444
auth = HTTPTokenAuth(scheme='Token')
4545
api_keys = os.environ.get('JUMPSTART_API_KEYS')
46+
GOOGLE_CLIENT_SECERTS_JSON = os.environ.get('GOOGLE_CLIENT_SECRETS_JSON')
47+
48+
calendar_service = get_calendar_service(GOOGLE_CLIENT_SECERTS_JSON)
4649

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

jumpstart/google.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
import os
2+
import json
23
from apiclient.discovery import build
34
from oauth2client.service_account import ServiceAccountCredentials
45

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

7-
def get_service(api_name, api_version, scopes, key_file_location):
8+
def get_service(api_name, api_version, scopes, key_file_contents):
89
"""Get a service that communicates to a Google API.
910
1011
Args:
1112
api_name: The name of the api to connect to.
1213
api_version: The api version to connect to.
1314
scopes: A list auth scopes to authorize for the application.
14-
key_file_location: The path to a valid service account JSON key file.
15+
key_file_contents: The contents of json keyfile.
1516
1617
Returns:
1718
A service that is connected to the specified API.
1819
"""
1920

20-
credentials = ServiceAccountCredentials.from_json_keyfile_name(key_file_location, scopes=scopes)
21+
key_file_json = json.loads(key_file_contents)
22+
23+
credentials = ServiceAccountCredentials.from_json_keyfile_dict(key_file_json, scopes=scopes)
2124

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

2528
return service
2629

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

0 commit comments

Comments
 (0)