This code is here to address the Sqreen technical exercise
You need to deploy this code on a host that is reachable by Sqreen.
You can run it on your localhost and open a specific port on your Internet Service Provider box.
Then you can check your public IP on https://www.whatismyip.com/
You need to know the configuration of your email provider.
For Gmail:
- Activate 2-step auth
- Create App Password https://support.google.com/accounts/answer/185833?hl=en
EMAIL_SMTP_HOST="smtp.gmail.com"
EMAIL_SMTP_TLS_PORT=587
- Create an account at https://my.sqreen.com/
- Fetch your organization token. From the Sqreen Dashboard, access Account Settings > Environments & Tokens.
Your token begins with env_org_. Take note of the token. - Configure sqreen.ini
# Replace the values for app_name and token with your own
cat > sqreen.ini <<EOF
[sqreen]
app_name: YOUR_APPLICATION_NAME
token: SQREEN_TOKEN
EOF
more info: https://docs.sqreen.com/python/installation/
- In the Sqreen Dashboard, from the application to connect, navigate to Settings > Integrations.
- In the Webhook pane, enter the URL. It's the public HOST of this app aka the destination to which you wish to POST messages from Sqreen (http://<your_ip>:8000/api/notifications).
Retrieve the secret. This secret will be used to validate the message was emitted by Sqreen.
You will add this to your .env file as SQREEN_NOTIFICATIONS_KEY. - Test, then Save the configuration.
more info: https://docs.sqreen.com/integrations/webhooks/
Copy .env.example to .env Configure your .env file with the necessary information
SQREEN_NOTIFICATIONS_KEY="GET FROM SQREEN"
EMAIL_PASSWORD="TBD"
EMAIL_SMTP_HOST="TBD"
EMAIL_SMTP_TLS_PORT=587
EMAIL_SENDER="your@email.com"
EMAIL_RECEIVER="your@email.com"
Please go through Pre-requisites
.env
sqreen.ini
docker build . -t sqreen_backend
docker run -d -p 8000:8000 sqreen_backend
- python3.8
- pip
curl https://bootstrap.pypa.io/get-pip.py | python3
pip3 install virtualenv
python3 -m virtualenv venv
source venv/bin/activate
deactivate
pip3 install -r requirements.txt
note: after the first install, when using virtual env, you need to deactivate and reactivate in order to have pytest available.
python3 -m pytest
python3 -m pytest -s # with debugging output
python3 -m pytest --cov=project test/ # check code coverage of the tests
coverage html
python3 -m ptw
python3 -m ptw -- -s # with debugging output
python3 setup.py install
python3 run.py
gunicorn wsgi:app -w 4 -b 0.0.0.0:8000