feat(phase-2): implement domain verification system
Implements complete domain verification flow with: - rel=me link verification service - HTML fetching with security controls - Rate limiting to prevent abuse - Email validation utilities - Authorization and verification API endpoints - User-facing templates for authorization and verification flows This completes Phase 2: Domain Verification as designed. Tests: - All Phase 2 unit tests passing - Coverage: 85% overall - Migration tests updated 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
87
src/gondulf/dependencies.py
Normal file
87
src/gondulf/dependencies.py
Normal file
@@ -0,0 +1,87 @@
|
||||
"""FastAPI dependency injection for services."""
|
||||
from functools import lru_cache
|
||||
|
||||
from gondulf.config import Config
|
||||
from gondulf.database.connection import Database
|
||||
from gondulf.dns import DNSService
|
||||
from gondulf.email import EmailService
|
||||
from gondulf.services.domain_verification import DomainVerificationService
|
||||
from gondulf.services.html_fetcher import HTMLFetcherService
|
||||
from gondulf.services.rate_limiter import RateLimiter
|
||||
from gondulf.services.relme_parser import RelMeParser
|
||||
from gondulf.storage import CodeStore
|
||||
|
||||
|
||||
# Configuration
|
||||
@lru_cache
|
||||
def get_config() -> Config:
|
||||
"""Get configuration instance."""
|
||||
return Config
|
||||
|
||||
|
||||
# Phase 1 Services
|
||||
@lru_cache
|
||||
def get_database() -> Database:
|
||||
"""Get singleton database service."""
|
||||
config = get_config()
|
||||
db = Database(config.DATABASE_URL)
|
||||
db.initialize()
|
||||
return db
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_code_storage() -> CodeStore:
|
||||
"""Get singleton code storage service."""
|
||||
config = get_config()
|
||||
return CodeStore(ttl_seconds=config.CODE_EXPIRY)
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_email_service() -> EmailService:
|
||||
"""Get singleton email service."""
|
||||
config = get_config()
|
||||
return EmailService(
|
||||
smtp_host=config.SMTP_HOST,
|
||||
smtp_port=config.SMTP_PORT,
|
||||
smtp_from=config.SMTP_FROM,
|
||||
smtp_username=config.SMTP_USERNAME,
|
||||
smtp_password=config.SMTP_PASSWORD,
|
||||
smtp_use_tls=config.SMTP_USE_TLS
|
||||
)
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_dns_service() -> DNSService:
|
||||
"""Get singleton DNS service."""
|
||||
return DNSService()
|
||||
|
||||
|
||||
# Phase 2 Services
|
||||
@lru_cache
|
||||
def get_html_fetcher() -> HTMLFetcherService:
|
||||
"""Get singleton HTML fetcher service."""
|
||||
return HTMLFetcherService()
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_relme_parser() -> RelMeParser:
|
||||
"""Get singleton rel=me parser service."""
|
||||
return RelMeParser()
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_rate_limiter() -> RateLimiter:
|
||||
"""Get singleton rate limiter service."""
|
||||
return RateLimiter(max_attempts=3, window_hours=1)
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_verification_service() -> DomainVerificationService:
|
||||
"""Get singleton domain verification service."""
|
||||
return DomainVerificationService(
|
||||
dns_service=get_dns_service(),
|
||||
email_service=get_email_service(),
|
||||
code_storage=get_code_storage(),
|
||||
html_fetcher=get_html_fetcher(),
|
||||
relme_parser=get_relme_parser()
|
||||
)
|
||||
Reference in New Issue
Block a user