Skip to content

Commit 18fc29c

Browse files
authored
Merge branch 'dev' into 232-reset-password-view
2 parents 734c382 + 16ebd1c commit 18fc29c

File tree

19 files changed

+234
-45
lines changed

19 files changed

+234
-45
lines changed

.travis.yml

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,57 @@ services:
1111
- mysql
1212
- redis
1313

14+
before_install:
15+
- openssl aes-256-cbc -K $encrypted_3c84dcdc6bbe_key -iv $encrypted_3c84dcdc6bbe_iv -in .env.enc -out .env -d
16+
# login to github registry
17+
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin docker.pkg.github.com
18+
1419
jobs:
1520
include:
16-
- stage: build
21+
- stage: Build Backend
1722
script:
18-
- openssl aes-256-cbc -K $encrypted_3c84dcdc6bbe_key -iv $encrypted_3c84dcdc6bbe_iv -in .env.enc -out .env -d
19-
# login to github registry
20-
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin docker.pkg.github.com
2123
# build image
22-
- docker build -t docker.pkg.github.com/seluj78/pymatcha/pymatcha-api:latest . -f backend.Dockerfile
24+
- docker build -t docker.pkg.github.com/seluj78/pymatcha/pymatcha-backend:$TRAVIS_COMMIT . -f backend.Dockerfile
25+
after_success:
2326
# push image
24-
- docker push docker.pkg.github.com/seluj78/pymatcha/pymatcha-api:latest
25-
- stage: test
26-
before_script:
27-
- node --version
28-
- npm --version
29-
- npm install -g newman
30-
- newman --version
27+
- docker push docker.pkg.github.com/seluj78/pymatcha/pymatcha-backend:$TRAVIS_COMMIT
28+
29+
- stage: Build Frontend
30+
script:
31+
# build image
32+
- docker build -t docker.pkg.github.com/seluj78/pymatcha/pymatcha-frontend:$TRAVIS_COMMIT . -f frontend.Dockerfile
33+
after_success:
34+
# push image
35+
- docker push docker.pkg.github.com/seluj78/pymatcha/pymatcha-frontend:$TRAVIS_COMMIT
36+
37+
- stage: Build Workers
38+
script:
39+
# build image
40+
- docker build -t docker.pkg.github.com/seluj78/pymatcha/pymatcha-workers:$TRAVIS_COMMIT . -f workers.Dockerfile
41+
after_success:
42+
# push image
43+
- docker push docker.pkg.github.com/seluj78/pymatcha/pymatcha-workers:$TRAVIS_COMMIT
44+
45+
- stage: Test API
46+
install:
3147
- wget https://repo.mysql.com//mysql-apt-config_0.8.15-1_all.deb
3248
- sudo dpkg -i mysql-apt-config_0.8.15-1_all.deb
3349
- sudo apt-get update -q
3450
- sudo apt-get install -q -y --allow-unauthenticated -o Dpkg::Options::=--force-confnew mysql-server
3551
- sudo systemctl restart mysql
3652
- sudo mysql_upgrade
53+
- npm install -g newman
54+
before_script:
55+
- node --version
56+
- npm --version
57+
- newman --version
3758
- mysql --version
3859
- mysql -e 'CREATE DATABASE pymatcha;'
60+
# pull image
61+
- docker pull docker.pkg.github.com/seluj78/pymatcha/pymatcha-backend:$TRAVIS_COMMIT
3962
script:
40-
# login to github registry
41-
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin docker.pkg.github.com
42-
# pull images
43-
- docker pull docker.pkg.github.com/seluj78/pymatcha/pymatcha-api:latest
44-
# decrypt the env file
45-
- openssl aes-256-cbc -K $encrypted_3c84dcdc6bbe_key -iv $encrypted_3c84dcdc6bbe_iv -in .env.enc -out .env -d
4663
# Run the backend api
47-
- docker run -d -p 5000:5000 --restart always --env-file .env --network="host" docker.pkg.github.com/seluj78/pymatcha/pymatcha-api:latest
64+
- docker run -d -p 5000:5000 --restart always --env-file .env --network="host" docker.pkg.github.com/seluj78/pymatcha/pymatcha-backend:$TRAVIS_COMMIT
4865
# Wait for docker to be up
4966
- sleep 10
5067
# run newman tests
@@ -53,13 +70,29 @@ jobs:
5370
# stop and remove docker to prevent them from block port at next iteration/test
5471
- docker stop $(docker ps -a -q)
5572
- docker rm $(docker ps -a -q)
56-
- stage: lint
73+
74+
- stage: Lint Backend
5775
before_script:
5876
- pip install -r backend/requirements.txt
5977
script:
6078
- black --check backend/
6179
- flake8 backend/
6280

81+
- stage: Tag new releases
82+
if: branch = dev
83+
script:
84+
- docker pull docker.pkg.github.com/seluj78/pymatcha/pymatcha-backend:$TRAVIS_COMMIT
85+
- docker pull docker.pkg.github.com/seluj78/pymatcha/pymatcha-frontend:$TRAVIS_COMMIT
86+
- docker pull docker.pkg.github.com/seluj78/pymatcha/pymatcha-workers:$TRAVIS_COMMIT
87+
# Tag images
88+
- docker tag docker.pkg.github.com/seluj78/pymatcha/pymatcha-backend:$TRAVIS_COMMIT docker.pkg.github.com/seluj78/pymatcha/pymatcha-backend:latest
89+
- docker tag docker.pkg.github.com/seluj78/pymatcha/pymatcha-frontend:$TRAVIS_COMMIT docker.pkg.github.com/seluj78/pymatcha/pymatcha-frontend:latest
90+
- docker tag docker.pkg.github.com/seluj78/pymatcha/pymatcha-workers:$TRAVIS_COMMIT docker.pkg.github.com/seluj78/pymatcha/pymatcha-workers:latest
91+
# push image
92+
- docker push docker.pkg.github.com/seluj78/pymatcha/pymatcha-backend:latest
93+
- docker push docker.pkg.github.com/seluj78/pymatcha/pymatcha-frontend:latest
94+
- docker push docker.pkg.github.com/seluj78/pymatcha/pymatcha-workers:latest
95+
6396
notifications:
6497
email:
6598
recipients:

backend/PyMatcha/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import os
2222

2323
import pymysql
24+
import sentry_sdk
2425
from celery import Celery
2526
from dotenv import load_dotenv
2627
from flask import Flask
@@ -32,6 +33,9 @@
3233
from PyMatcha.utils.tables import create_tables
3334
from pymysql.cursors import DictCursor
3435
from redis import StrictRedis
36+
from sentry_sdk import configure_scope
37+
from sentry_sdk.integrations.flask import FlaskIntegration
38+
3539

3640
PYMATCHA_ROOT = os.path.join(os.path.dirname(__file__), "../..") # refers to application_top
3741
dotenv_path = os.path.join(PYMATCHA_ROOT, ".env")
@@ -79,6 +83,13 @@
7983
if ENABLE_LOGGING == "True":
8084
setup_logging()
8185

86+
sentry_sdk.init(
87+
dsn="https://bb17c14c99d448e2804bf2f105d4ec52@o450203.ingest.sentry.io/5434438",
88+
integrations=[FlaskIntegration()],
89+
traces_sample_rate=1.0,
90+
)
91+
92+
8293
application = Flask(__name__)
8394

8495
if os.getenv("FLASK_DEBUG", "false") == "true" or os.getenv("FLASK_DEBUG", "false") == "1":
@@ -183,6 +194,9 @@ def jwt_user_callback(identity):
183194
except NotFoundError:
184195
# The user who the server issues the token for was deleted in the db.
185196
return None
197+
198+
with configure_scope() as scope:
199+
scope.user = {"email": u.email, "id": u.id, "username": u.username}
186200
redis.set("online_user:" + str(identity["id"]), datetime.datetime.utcnow().timestamp())
187201
return u
188202

backend/PyMatcha/models/user.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def create(
8989
except ValueError:
9090
pass
9191
else:
92-
logging.error("Email {} taken".format(email))
92+
logging.warning("Email {} taken".format(email))
9393
raise ConflictError("Email {} taken.".format(email), "Use another email.")
9494

9595
# Check username availability
@@ -98,17 +98,17 @@ def create(
9898
except ValueError:
9999
pass
100100
else:
101-
logging.error("Username {} taken".format(username))
101+
logging.warning("Username {} taken".format(username))
102102
raise ConflictError("Username {} taken.".format(username), "Try another username.")
103103

104104
# Check correct gender
105105
if gender not in ["male", "female", "other"]:
106-
logging.error("Gender must be male, female or other, not {}".format(gender))
106+
logging.warning("Gender must be male, female or other, not {}".format(gender))
107107
raise ConflictError("Gender must be male, female or other, not {}.".format(gender))
108108

109109
# Check correct orientation
110110
if orientation not in ["heterosexual", "homosexual", "bisexual", "other"]:
111-
logging.error(
111+
logging.warning(
112112
"Sexual Orientation must be heterosexual, homosexual, bisexual or other, not {}.".format(orientation)
113113
)
114114
raise ConflictError(
@@ -119,7 +119,7 @@ def create(
119119
try:
120120
Geohash.decode(geohash)
121121
except ValueError as e:
122-
logging.error("Geohash error: {}".format(e))
122+
logging.warning("Geohash error: {}".format(e))
123123
raise e
124124

125125
# Encrypt password
@@ -166,7 +166,7 @@ def register(email: str, username: str, password: str, first_name: str, last_nam
166166
except ValueError:
167167
pass
168168
else:
169-
logging.error("Username {} taken".format(username))
169+
logging.warning("Username {} taken".format(username))
170170
raise ConflictError("Username {} taken.".format(username), "Try another username.")
171171

172172
# Encrypt password

backend/PyMatcha/routes/api/auth/register.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def api_create_user():
4949
last_name=data["last_name"],
5050
)
5151
except ConflictError as e:
52-
current_app.logger.fatal("Conflict error on user register: {}".format(e))
52+
current_app.logger.warning("Conflict error on user register: {}".format(e))
5353
raise e
5454
else:
5555
token = generate_confirmation_token(email=data["email"], token_type="confirm")

backend/PyMatcha/utils/confirm_token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
def generate_confirmation_token(email, token_type):
3030
logging.debug("Generating confirmation token for email {}".format(email))
3131
if token_type not in ACCEPTED_TOKEN_TYPES:
32-
logging.error("token_type must be of {} and is {}".format(ACCEPTED_TOKEN_TYPES, token_type))
32+
logging.warning("token_type must be of {} and is {}".format(ACCEPTED_TOKEN_TYPES, token_type))
3333
raise ValueError("Reset token type must be confirm or reset.")
3434
serializer = URLSafeTimedSerializer(application.config["FLASK_SECRET_KEY"])
3535
token = serializer.dumps(email + ":{}".format(token_type), salt=application.config["FLASK_SECRET_KEY"])

backend/PyMatcha/utils/errors/badrequest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
"""
1919
from PyMatcha import application
20+
from PyMatcha.utils.errors.base_class import CustomException
2021
from PyMatcha.utils.errors.template import generate_error_json
2122

2223

23-
class BadRequestError(Exception):
24+
class BadRequestError(CustomException):
2425
"""
2526
This is the BadRequestError class for the Exception.
2627
"""
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class CustomException(Exception):
2+
pass

backend/PyMatcha/utils/errors/conflict.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
"""
1919
from PyMatcha import application
20+
from PyMatcha.utils.errors.base_class import CustomException
2021
from PyMatcha.utils.errors.template import generate_error_json
2122

2223

23-
class ConflictError(Exception):
24+
class ConflictError(CustomException):
2425
"""
2526
This is the ConflictError class for the Exception.
2627
"""

backend/PyMatcha/utils/errors/forbidden.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
"""
1919
from PyMatcha import application
20+
from PyMatcha.utils.errors.base_class import CustomException
2021
from PyMatcha.utils.errors.template import generate_error_json
2122

2223

23-
class ForbiddenError(Exception):
24+
class ForbiddenError(CustomException):
2425
"""
2526
This is the ForbiddenError class for the Exception.
2627
"""

backend/PyMatcha/utils/errors/notfound.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
along with this program. If not, see <https://www.gnu.org/licenses/>.
1818
"""
1919
from PyMatcha import application
20+
from PyMatcha.utils.errors.base_class import CustomException
2021
from PyMatcha.utils.errors.template import generate_error_json
2122

2223

23-
class NotFoundError(Exception):
24+
class NotFoundError(CustomException):
2425
"""
2526
This is the NotFoundError class for the Exception.
2627
"""

0 commit comments

Comments
 (0)