Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/sentry implementation #203

Merged
merged 15 commits into from
Jul 11, 2024
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/super-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DEFAULT_BRANCH: main
VALIDATE_ALL_CODEBASE: false
VALIDATE_PYTHON_PYLINT: false
LINTER_RULES_PATH: /
PYTHON_BLACK_CONFIG_FILE: pyproject.toml
PYTHON_FLAKE8_CONFIG_FILE: .flake8
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ serve:
python manage.py runserver

serve-sso:
aws-sso exec --profile analytical-platform-development:AdministratorAccess -- python manage.py runserver
aws-sso exec --profile analytical-platform-compute-development:modernisation-platform-sandbox -- python manage.py runserver

build-container:
@ARCH=`uname -m`; \
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ If you are using a workspace with multiple applications, search for ```Dev Conta
There is an example environment file stored on 1Password named ```Analytical Platform UI Env```. Paste the contents into a new file called ```.env``` in the root of the project.

### Running Development Server
To run the server, you will need to use aws-sso cli. To find the correct profile, run ```aws-sso list``` in the terminal. This will provide you with a link to sign in via SSO. Once signed in, a list of profiles will be displayed. You are looking for the profile name linked to the ```analytical-platform-development``` AccountAlias.
To run the server, you will need to use aws-sso cli. To find the correct profile, run ```aws-sso list``` in the terminal. This will provide you with a link to sign in via SSO. Once signed in, a list of profiles will be displayed. You are looking for the profile name linked to the ```analytical-platform-compute-development``` AccountAlias.

To run the server using this profile, enter ```aws-sso exec --profile analytical-platform-development:AdministratorAccess -- python manage.py runserver``` or ```make serve-sso```. Then go to ```localhost:8000``` and sign in using your @justice.gov.uk identity.
To run the server using this profile, enter ```aws-sso exec --profile analytical-platform-compute-development:modernisation-platform-sandbox -- python manage.py runserver``` or ```make serve-sso```. Then go to ```localhost:8000``` and sign in using your @justice.gov.uk identity.

### Local debugging
Copy `launch.json.example`, `settings.json.example` and `tasks.json.example` from the examples folder into a `.vscode` folder in the root of the project and remove the `.example` suffix. To debug the application, go to the `run and debug` tab and select the `runserver` configuration. When starting debugging you may need to sign into AWS first. There will be a prompt in the terminal to do so.

To debug any tests, switch the debug configuration to `Python: Debug Tests` then go to the testing tab. From here you can run the full suite of tests or individual tests. You can also click the debug icon in order to debug any tests that are failing.

### Updating Migrations
To run the migrations locally, run ```python manage.py migrate``` in the terminal.
Expand Down
4 changes: 3 additions & 1 deletion ap/auth/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.urls import reverse
from django.views.generic import TemplateView, View

import sentry_sdk
from authlib.common.security import generate_token
from authlib.integrations.django_client import OAuthError

Expand Down Expand Up @@ -58,7 +59,8 @@ def get(self, request):
else:
self._login_success(request, user, token)
return redirect("/")
except OAuthError:
except OAuthError as error:
sentry_sdk.capture_exception(error)
return self._login_failure()


Expand Down
18 changes: 17 additions & 1 deletion ap/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
PROJECT_ROOT = dirname(DJANGO_ROOT)

# Name of the deployment environment (dev/prod)
ENV = os.environ.get("ENV", "dev")
ENV = os.environ.get("APP_ENVIRONMENT", "dev")

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
Expand Down Expand Up @@ -81,6 +81,22 @@
"django_structlog.middlewares.RequestMiddleware",
]

# -- Sentry error tracking

if os.environ.get("SENTRY_DSN"):
# Third-party
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

sentry_sdk.init(
dsn=os.environ["SENTRY_DSN"],
environment=ENV,
integrations=[DjangoIntegration()],
traces_sample_rate=0.0,
send_default_pii=True,
)


# The list of authentication backend used for checking user's access to app
AUTHENTICATION_BACKENDS = ["django.contrib.auth.backends.ModelBackend"]

Expand Down
4 changes: 2 additions & 2 deletions chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ apiVersion: v2
name: analytical-platform-ui
description: Analytical Platform UI
type: application
version: 0.0.0-rc0
appVersion: 0.0.0-rc0
version: 0.0.0-rc1
appVersion: 0.0.0-rc1
icon: https://upload.wikimedia.org/wikipedia/en/thumb/4/4a/Ministry_of_Justice_logo_%28United_Kingdom%29.svg/611px-Ministry_of_Justice_logo_%28United_Kingdom%29.svg.png
maintainers:
- name: moj-data-platform-robot
Expand Down
File renamed without changes.
30 changes: 30 additions & 0 deletions examples/launch.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "runserver",
"type": "debugpy",
"request": "launch",
"args": [
"runserver"
],
"django": true,
"autoStartBrowser": false,
"justMyCode": false,
"preLaunchTask": "aws-sso-process",
"program": "${workspaceFolder}/manage.py",
},
{
"name": "Python: Debug Tests",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"purpose": ["debug-test"],
"console": "integratedTerminal",
"justMyCode": false,
"env": {
"DJANGO_SETTINGS_MODULE": "ap.settings.test"
}
}
]
}
4 changes: 4 additions & 0 deletions examples/settings.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
12 changes: 12 additions & 0 deletions examples/tasks.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "aws-sso-process",
"type": "shell",
"command": "aws-sso process --sts-refresh --profile analytical-platform-compute-development:modernisation-platform-sandbox"
}
]
}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ pytest==8.0.0
pytest-django==4.8.0
python-dotenv==1.0.1
requests==2.32.3
sentry-sdk==2.9.0
uvicorn[standard]==0.30.1
Loading