Tidy up homepage and navigation

This commit is contained in:
Dan Milne
2025-11-09 20:58:13 +11:00
parent c9e2992fe0
commit 1f4428348d
56 changed files with 2822 additions and 955 deletions

View File

@@ -3,24 +3,24 @@
class DsnAuthenticationService
class AuthenticationError < StandardError; end
def self.authenticate(request, project_id)
def self.authenticate(request)
# Try multiple authentication methods in order of preference
# Method 1: Query parameter authentication
public_key = extract_key_from_query_params(request)
return find_project(public_key, project_id) if public_key
dsn_key = extract_key_from_query_params(request)
return find_dsn(dsn_key) if dsn_key
# Method 2: X-Baffle-Auth header (similar to X-Sentry-Auth)
public_key = extract_key_from_baffle_auth_header(request)
return find_project(public_key, project_id) if public_key
dsn_key = extract_key_from_baffle_auth_header(request)
return find_dsn(dsn_key) if dsn_key
# Method 3: Authorization Bearer token
public_key = extract_key_from_authorization_header(request)
return find_project(public_key, project_id) if public_key
dsn_key = extract_key_from_authorization_header(request)
return find_dsn(dsn_key) if dsn_key
# Method 4: Basic auth (username is the public_key)
public_key = extract_key_from_basic_auth(request)
return find_project(public_key, project_id) if public_key
# Method 4: Basic auth (username is the dsn_key)
dsn_key = extract_key_from_basic_auth(request)
return find_dsn(dsn_key) if dsn_key
raise AuthenticationError, "No valid authentication method found"
end
@@ -36,8 +36,8 @@ class DsnAuthenticationService
auth_header = request.headers['X-Baffle-Auth'] || request.headers['X-Sentry-Auth']
return nil unless auth_header
# Parse: Baffle baffle_key=public_key, baffle_version=1
# Or: Sentry sentry_key=public_key, sentry_version=7
# Parse: Baffle baffle_key=dsn_key, baffle_version=1
# Or: Sentry sentry_key=dsn_key, sentry_version=7
match = auth_header.match(/(?:baffle_key|sentry_key)=([^,\s]+)/)
match&.[](1)
end
@@ -46,7 +46,7 @@ class DsnAuthenticationService
authorization_header = request.headers['Authorization']
return nil unless authorization_header
# Parse: Bearer public_key
# Parse: Bearer dsn_key
if authorization_header.start_with?('Bearer ')
authorization_header[7..-1].strip
end
@@ -62,20 +62,16 @@ class DsnAuthenticationService
username
end
def self.find_project(public_key, project_id)
return nil unless public_key.present? && project_id.present?
def self.find_dsn(dsn_key)
return nil unless dsn_key.present?
# Find project by public_key first
project = Project.find_by(public_key: public_key)
raise AuthenticationError, "Invalid public_key" unless project
# Find DSN by key
dsn = Dsn.authenticate(dsn_key)
raise AuthenticationError, "Invalid DSN key" unless dsn
# Verify project_id matches (supports both slug and ID)
project_matches = Project.find_by(slug: project_id) || Project.find_by(id: project_id)
raise AuthenticationError, "Invalid project_id" unless project_matches == project
# Ensure DSN is enabled
raise AuthenticationError, "DSN is disabled" unless dsn.enabled?
# Ensure project is enabled
raise AuthenticationError, "Project is disabled" unless project.enabled?
project
dsn
end
end