mirror of
https://github.com/jlengrand/bugsink.git
synced 2026-03-10 08:01:17 +00:00
DSN added to project admin
This commit is contained in:
@@ -134,9 +134,11 @@ STATICFILES_DIRS = [
|
||||
# no support for uuid in this setting yet (https://code.djangoproject.com/ticket/32577) so we leave it as-is
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
# ###################### MOST PER-SITE CONFIG BELOW THIS LINE ###################
|
||||
|
||||
# {PROTOCOL}://{PUBLIC_KEY}:{SECRET_KEY}@{HOST}{PATH}/{PROJECT_ID}
|
||||
SENTRY_DSN = os.getenv("SENTRY_DSN") # "http://ignored_public_key:ignored_secret_key@127.0.0.1:9000/1"
|
||||
|
||||
# {PROTOCOL}://{PUBLIC_KEY}:{DEPRECATED_SECRET_KEY}@{HOST}{PATH}/{PROJECT_ID}
|
||||
SENTRY_DSN = os.getenv("SENTRY_DSN")
|
||||
|
||||
|
||||
if SENTRY_DSN is not None:
|
||||
@@ -146,3 +148,5 @@ if SENTRY_DSN is not None:
|
||||
auto_session_tracking=False,
|
||||
traces_sample_rate=0,
|
||||
)
|
||||
|
||||
BASE_URL = "http://glitchtip:9000" # no trailing slash
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
import urllib.parse
|
||||
|
||||
|
||||
def _colon_port(port):
|
||||
return ":" + str(port) if port else ""
|
||||
|
||||
|
||||
def build_dsn(base_url, project_id, public_key):
|
||||
parts = urllib.parse.urlsplit(base_url)
|
||||
return (f"{ parts.scheme }://{ public_key }@{ parts.hostname }{ _colon_port(parts.port) }" +
|
||||
f"{ parts.path }/{ project_id }")
|
||||
|
||||
|
||||
def _get_url(sentry_dsn, ingest_method):
|
||||
# https://github.com/getsentry/develop/blob/b24a602de05b/src/docs/sdk/overview.mdx#L94
|
||||
|
||||
@@ -10,7 +20,7 @@ def _get_url(sentry_dsn, ingest_method):
|
||||
path_before_api, project_id = parts.path.rsplit("/", 1)
|
||||
|
||||
return (
|
||||
parts.scheme + "://" + parts.hostname + (":" + str(parts.port) if parts.port else "") +
|
||||
parts.scheme + "://" + parts.hostname + _colon_port(parts.port) +
|
||||
path_before_api + "/api/" + project_id + "/" + ingest_method + "/")
|
||||
|
||||
|
||||
|
||||
@@ -2,12 +2,26 @@ from unittest import TestCase
|
||||
import datetime
|
||||
from django.test import override_settings
|
||||
|
||||
from .dsn import get_store_url, get_envelope_url, get_header_value
|
||||
from .dsn import build_dsn, get_store_url, get_envelope_url, get_header_value
|
||||
from .auth import parse_auth_header_value
|
||||
from .timestamp import parse_timestamp
|
||||
|
||||
|
||||
class DsnTestCase(TestCase):
|
||||
def test_build_dsn(self):
|
||||
self.assertEquals(
|
||||
"https://public_key@hosted.bugsink/1",
|
||||
build_dsn("https://hosted.bugsink", "1", "public_key"))
|
||||
|
||||
self.assertEquals(
|
||||
"https://public_key@hosted.bugsink/foo/1",
|
||||
build_dsn("https://hosted.bugsink/foo", "1", "public_key"))
|
||||
|
||||
def test_build_dsn_non_default_port(self):
|
||||
self.assertEquals(
|
||||
"https://public_key@hosted.bugsink:9000/1",
|
||||
build_dsn("https://hosted.bugsink:9000", "1", "public_key"))
|
||||
|
||||
def test_get_store_url(self):
|
||||
self.assertEquals(
|
||||
"https://hosted.bugsink/api/1/store/",
|
||||
|
||||
@@ -5,4 +5,10 @@ from .models import Project
|
||||
|
||||
@admin.register(Project)
|
||||
class ProjectAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
list_display = [
|
||||
'name',
|
||||
'dsn',
|
||||
]
|
||||
readonly_fields = [
|
||||
'dsn',
|
||||
]
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import uuid
|
||||
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
|
||||
from compat.dsn import build_dsn
|
||||
|
||||
|
||||
class Project(models.Model):
|
||||
@@ -27,9 +30,9 @@ class Project(models.Model):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def get_dsn(self):
|
||||
# TODO, because the server needs to know its own address
|
||||
return get_dsn()
|
||||
@property
|
||||
def dsn(self):
|
||||
return build_dsn(settings.BASE_URL, self.id, self.sentry_key)
|
||||
|
||||
"""
|
||||
# TODO is this even more efficient?
|
||||
|
||||
Reference in New Issue
Block a user