infrastructure.enrichers.location_enricher¶
src.infrastructure.enrichers.location_enricher
¶
Location enricher implementation for IP geolocation.
Resolves IP addresses to geographic locations using MaxMind GeoIP2.
Implementation
- Uses GeoLite2-City database for city-level geolocation
- Fail-open: Returns empty result on any errors
- Private IPs: Returns empty (no meaningful location)
- TODO: F7.3 - Automate monthly database updates via background jobs
Reference
- docs/architecture/session-management-architecture.md
- MaxMind GeoIP2: https://dev.maxmind.com/geoip/docs/databases/city-and-country
Classes¶
IPLocationEnricher
¶
Location enricher for IP geolocation using MaxMind GeoIP2.
Uses GeoLite2-City database to resolve IP addresses to geographic locations. Database is updated monthly (manual for now, automated in F7.3).
Implements LocationEnricher protocol (structural typing).
Behavior
- Fail-open: Returns empty result on errors (never blocks session creation)
- Private IPs: Always return empty (no meaningful location data)
- Best-effort: Unknown IPs return empty data
- Lazy loading: Database reader initialized on first use
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_path
|
str | None
|
Path to GeoLite2-City.mmdb file. If None, geolocation is disabled. |
None
|
Source code in src/infrastructure/enrichers/location_enricher.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
Functions¶
__init__
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
LoggerProtocol
|
Logger for error/debug messages. |
required |
db_path
|
str | None
|
Path to GeoIP2 database file. Defaults to settings.geoip_db_path. |
None
|
Source code in src/infrastructure/enrichers/location_enricher.py
enrich
async
¶
Resolve IP address to geographic location using GeoIP2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ip_address
|
str
|
Client IP address (IPv4 or IPv6). |
required |
Returns:
| Type | Description |
|---|---|
LocationEnrichmentResult
|
LocationEnrichmentResult with location data. |
LocationEnrichmentResult
|
Returns empty result for: |
LocationEnrichmentResult
|
|
LocationEnrichmentResult
|
|
LocationEnrichmentResult
|
|
LocationEnrichmentResult
|
|