Documentation
ΒΆ
Index ΒΆ
- type APIConfig
- type BunRepository
- func (r *BunRepository) ApproveTravel(ctx context.Context, alertID xid.ID, approvedBy xid.ID) error
- func (r *BunRepository) CreateLocationEvent(ctx context.Context, event *LocationEvent) error
- func (r *BunRepository) CreateRule(ctx context.Context, rule *GeofenceRule) error
- func (r *BunRepository) CreateTravelAlert(ctx context.Context, alert *TravelAlert) error
- func (r *BunRepository) CreateTrustedLocation(ctx context.Context, location *TrustedLocation) error
- func (r *BunRepository) CreateViolation(ctx context.Context, violation *GeofenceViolation) error
- func (r *BunRepository) DeleteExpiredCache(ctx context.Context) (int64, error)
- func (r *BunRepository) DeleteOldLocationEvents(ctx context.Context, before time.Time) (int64, error)
- func (r *BunRepository) DeleteRule(ctx context.Context, id xid.ID) error
- func (r *BunRepository) DeleteTrustedLocation(ctx context.Context, id xid.ID) error
- func (r *BunRepository) DenyTravel(ctx context.Context, alertID xid.ID, deniedBy xid.ID) error
- func (r *BunRepository) GetAppViolations(ctx context.Context, appID xid.ID, limit int) ([]*GeofenceViolation, error)
- func (r *BunRepository) GetCachedGeoData(ctx context.Context, ip string) (*GeoCache, error)
- func (r *BunRepository) GetLastLocation(ctx context.Context, userID xid.ID, appID xid.ID) (*GeoData, error)
- func (r *BunRepository) GetLastLocationEvent(ctx context.Context, userID xid.ID) (*LocationEvent, error)
- func (r *BunRepository) GetLocationEvent(ctx context.Context, id xid.ID) (*LocationEvent, error)
- func (r *BunRepository) GetPendingTravelAlerts(ctx context.Context, appID xid.ID) ([]*TravelAlert, error)
- func (r *BunRepository) GetRule(ctx context.Context, id xid.ID) (*GeofenceRule, error)
- func (r *BunRepository) GetRulesByApp(ctx context.Context, appID xid.ID) ([]*GeofenceRule, error)
- func (r *BunRepository) GetRulesByUser(ctx context.Context, userID xid.ID) ([]*GeofenceRule, error)
- func (r *BunRepository) GetTravelAlert(ctx context.Context, id xid.ID) (*TravelAlert, error)
- func (r *BunRepository) GetTrustedLocation(ctx context.Context, id xid.ID) (*TrustedLocation, error)
- func (r *BunRepository) GetUnresolvedViolations(ctx context.Context, appID xid.ID) ([]*GeofenceViolation, error)
- func (r *BunRepository) GetUserLocationHistory(ctx context.Context, userID xid.ID, limit int) ([]*LocationEvent, error)
- func (r *BunRepository) GetUserTravelAlerts(ctx context.Context, userID xid.ID, status string) ([]*TravelAlert, error)
- func (r *BunRepository) GetUserTrustedLocations(ctx context.Context, userID xid.ID) ([]*TrustedLocation, error)
- func (r *BunRepository) GetUserViolations(ctx context.Context, userID xid.ID, limit int) ([]*GeofenceViolation, error)
- func (r *BunRepository) GetViolation(ctx context.Context, id xid.ID) (*GeofenceViolation, error)
- func (r *BunRepository) IsLocationTrusted(ctx context.Context, userID xid.ID, lat, lon float64) (bool, *TrustedLocation, error)
- func (r *BunRepository) ListEnabledRules(ctx context.Context, appID xid.ID, userID *xid.ID) ([]*GeofenceRule, error)
- func (r *BunRepository) ResolveViolation(ctx context.Context, id xid.ID, resolvedBy xid.ID, resolution string) error
- func (r *BunRepository) SetCachedGeoData(ctx context.Context, cache *GeoCache) error
- func (r *BunRepository) UpdateRule(ctx context.Context, rule *GeofenceRule) error
- func (r *BunRepository) UpdateTravelAlert(ctx context.Context, alert *TravelAlert) error
- func (r *BunRepository) UpdateTrustedLocation(ctx context.Context, location *TrustedLocation) error
- type CachedDetection
- type CachedGeo
- type Config
- type CorporateConfig
- type DetectionConfig
- type DetectionProvider
- type DetectionResult
- type ErrorResponse
- type GPSConfig
- type GPSData
- type GeoCache
- type GeoData
- type GeoProvider
- type Geofence
- type GeofenceCheckResponse
- type GeofenceErrorResponse
- type GeofenceEventResponse
- type GeofenceEventsResponse
- type GeofenceLocationAnalyticsResponse
- type GeofenceLookupResponse
- type GeofenceMetricsResponse
- type GeofenceRule
- type GeofenceRuleResponse
- type GeofenceRulesResponse
- type GeofenceStatusResponse
- type GeofenceTravelAlertResponse
- type GeofenceTravelAlertsResponse
- type GeofenceTrustedLocationResponse
- type GeofenceTrustedLocationsResponse
- type GeofenceViolation
- type GeofenceViolationAnalyticsResponse
- type GeofenceViolationResponse
- type GeofenceViolationsResponse
- type GeolocationConfig
- type Handler
- func (h *Handler) ApproveTravelAlert(c forge.Context) error
- func (h *Handler) CheckLocation(c forge.Context) error
- func (h *Handler) CreateRule(c forge.Context) error
- func (h *Handler) CreateTrustedLocation(c forge.Context) error
- func (h *Handler) DeleteRule(c forge.Context) error
- func (h *Handler) DeleteTrustedLocation(c forge.Context) error
- func (h *Handler) DenyTravelAlert(c forge.Context) error
- func (h *Handler) GetLocationAnalytics(c forge.Context) error
- func (h *Handler) GetLocationEvent(c forge.Context) error
- func (h *Handler) GetMetrics(c forge.Context) error
- func (h *Handler) GetRule(c forge.Context) error
- func (h *Handler) GetTravelAlert(c forge.Context) error
- func (h *Handler) GetTrustedLocation(c forge.Context) error
- func (h *Handler) GetViolation(c forge.Context) error
- func (h *Handler) GetViolationAnalytics(c forge.Context) error
- func (h *Handler) ListLocationEvents(c forge.Context) error
- func (h *Handler) ListRules(c forge.Context) error
- func (h *Handler) ListTravelAlerts(c forge.Context) error
- func (h *Handler) ListTrustedLocations(c forge.Context) error
- func (h *Handler) ListViolations(c forge.Context) error
- func (h *Handler) LookupIP(c forge.Context) error
- func (h *Handler) ResolveViolation(c forge.Context) error
- func (h *Handler) UpdateRule(c forge.Context) error
- func (h *Handler) UpdateTrustedLocation(c forge.Context) error
- type IPAPIProvider
- type IPGeolocationProvider
- type IPInfoProvider
- type IPQSProvider
- type LocationCheckRequest
- type LocationCheckResult
- type LocationEvent
- type MaxMindProvider
- type MessageResponse
- type Middleware
- func (m *Middleware) BlockProxy(next func(forge.Context) error) func(forge.Context) error
- func (m *Middleware) BlockTor(next func(forge.Context) error) func(forge.Context) error
- func (m *Middleware) BlockVPN(next func(forge.Context) error) func(forge.Context) error
- func (m *Middleware) CheckGeofence(next func(forge.Context) error) func(forge.Context) error
- func (m *Middleware) RequireCountry(countries ...string) func(next func(forge.Context) error) func(forge.Context) error
- func (m *Middleware) RequireLocation(next func(forge.Context) error) func(forge.Context) error
- type NotificationConfig
- type Plugin
- func (p *Plugin) Config() *Config
- func (p *Plugin) Description() string
- func (p *Plugin) Health(ctx context.Context) error
- func (p *Plugin) ID() string
- func (p *Plugin) Init(auth interface{}) error
- func (p *Plugin) Middleware() func(next func(forge.Context) error) func(forge.Context) error
- func (p *Plugin) Migrate() error
- func (p *Plugin) Name() string
- func (p *Plugin) RegisterHooks(hookRegistry *hooks.HookRegistry) error
- func (p *Plugin) RegisterRoutes(router forge.Router) error
- func (p *Plugin) RegisterServiceDecorators(services *registry.ServiceRegistry) error
- func (p *Plugin) Service() *Service
- func (p *Plugin) Shutdown(ctx context.Context) error
- func (p *Plugin) Version() string
- type ProxyCheckProvider
- type Repository
- type RestrictionConfig
- type RulesResponse
- type SecurityConfig
- type Service
- func (s *Service) CheckLocation(ctx context.Context, req *LocationCheckRequest) (*LocationCheckResult, error)
- func (s *Service) CheckSessionSecurity(ctx context.Context, userID xid.ID, appID xid.ID, ipAddress string) error
- func (s *Service) GetDetection(ctx context.Context, ip string) (*DetectionResult, error)
- func (s *Service) GetGeolocation(ctx context.Context, ip string) (*GeoData, error)
- type SessionConfig
- type StaticDetectionProvider
- func (p *StaticDetectionProvider) AddDatacenter(ip string)
- func (p *StaticDetectionProvider) AddProxy(ip string)
- func (p *StaticDetectionProvider) AddTor(ip string)
- func (p *StaticDetectionProvider) AddVPN(ip string)
- func (p *StaticDetectionProvider) Check(ctx context.Context, ip string) (*DetectionResult, error)
- func (p *StaticDetectionProvider) Name() string
- type StatusResponse
- type SuccessResponse
- type TimeRestriction
- type TimeRestrictionRule
- type TravelAlert
- type TravelConfig
- type TrustedLocation
- type VPNAPIProvider
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
type APIConfig ΒΆ
type APIConfig struct {
BasePath string `json:"basePath" yaml:"basePath"`
EnableManagement bool `json:"enableManagement" yaml:"enableManagement"`
EnableValidation bool `json:"enableValidation" yaml:"enableValidation"`
EnableMetrics bool `json:"enableMetrics" yaml:"enableMetrics"`
EnableRealtime bool `json:"enableRealtime" yaml:"enableRealtime"` // WebSocket for live tracking
}
APIConfig configures geofencing API endpoints
type BunRepository ΒΆ
type BunRepository struct {
// contains filtered or unexported fields
}
BunRepository implements Repository using Bun ORM
func (*BunRepository) ApproveTravel ΒΆ
func (*BunRepository) CreateLocationEvent ΒΆ
func (r *BunRepository) CreateLocationEvent(ctx context.Context, event *LocationEvent) error
Location Events
func (*BunRepository) CreateRule ΒΆ
func (r *BunRepository) CreateRule(ctx context.Context, rule *GeofenceRule) error
Rules
func (*BunRepository) CreateTravelAlert ΒΆ
func (r *BunRepository) CreateTravelAlert(ctx context.Context, alert *TravelAlert) error
Travel Alerts
func (*BunRepository) CreateTrustedLocation ΒΆ
func (r *BunRepository) CreateTrustedLocation(ctx context.Context, location *TrustedLocation) error
Trusted Locations
func (*BunRepository) CreateViolation ΒΆ
func (r *BunRepository) CreateViolation(ctx context.Context, violation *GeofenceViolation) error
Violations
func (*BunRepository) DeleteExpiredCache ΒΆ
func (r *BunRepository) DeleteExpiredCache(ctx context.Context) (int64, error)
func (*BunRepository) DeleteOldLocationEvents ΒΆ
func (*BunRepository) DeleteRule ΒΆ
func (*BunRepository) DeleteTrustedLocation ΒΆ
func (*BunRepository) DenyTravel ΒΆ
func (*BunRepository) GetAppViolations ΒΆ added in v0.0.6
func (r *BunRepository) GetAppViolations(ctx context.Context, appID xid.ID, limit int) ([]*GeofenceViolation, error)
func (*BunRepository) GetCachedGeoData ΒΆ
Geo Cache
func (*BunRepository) GetLastLocation ΒΆ added in v0.0.6
func (r *BunRepository) GetLastLocation(ctx context.Context, userID xid.ID, appID xid.ID) (*GeoData, error)
GetLastLocation retrieves the most recent location for a user as GeoData
func (*BunRepository) GetLastLocationEvent ΒΆ
func (r *BunRepository) GetLastLocationEvent(ctx context.Context, userID xid.ID) (*LocationEvent, error)
func (*BunRepository) GetLocationEvent ΒΆ
func (r *BunRepository) GetLocationEvent(ctx context.Context, id xid.ID) (*LocationEvent, error)
func (*BunRepository) GetPendingTravelAlerts ΒΆ
func (r *BunRepository) GetPendingTravelAlerts(ctx context.Context, appID xid.ID) ([]*TravelAlert, error)
func (*BunRepository) GetRule ΒΆ
func (r *BunRepository) GetRule(ctx context.Context, id xid.ID) (*GeofenceRule, error)
func (*BunRepository) GetRulesByApp ΒΆ added in v0.0.6
func (r *BunRepository) GetRulesByApp(ctx context.Context, appID xid.ID) ([]*GeofenceRule, error)
func (*BunRepository) GetRulesByUser ΒΆ
func (r *BunRepository) GetRulesByUser(ctx context.Context, userID xid.ID) ([]*GeofenceRule, error)
func (*BunRepository) GetTravelAlert ΒΆ
func (r *BunRepository) GetTravelAlert(ctx context.Context, id xid.ID) (*TravelAlert, error)
func (*BunRepository) GetTrustedLocation ΒΆ
func (r *BunRepository) GetTrustedLocation(ctx context.Context, id xid.ID) (*TrustedLocation, error)
func (*BunRepository) GetUnresolvedViolations ΒΆ
func (r *BunRepository) GetUnresolvedViolations(ctx context.Context, appID xid.ID) ([]*GeofenceViolation, error)
func (*BunRepository) GetUserLocationHistory ΒΆ
func (r *BunRepository) GetUserLocationHistory(ctx context.Context, userID xid.ID, limit int) ([]*LocationEvent, error)
func (*BunRepository) GetUserTravelAlerts ΒΆ
func (r *BunRepository) GetUserTravelAlerts(ctx context.Context, userID xid.ID, status string) ([]*TravelAlert, error)
func (*BunRepository) GetUserTrustedLocations ΒΆ
func (r *BunRepository) GetUserTrustedLocations(ctx context.Context, userID xid.ID) ([]*TrustedLocation, error)
func (*BunRepository) GetUserViolations ΒΆ
func (r *BunRepository) GetUserViolations(ctx context.Context, userID xid.ID, limit int) ([]*GeofenceViolation, error)
func (*BunRepository) GetViolation ΒΆ
func (r *BunRepository) GetViolation(ctx context.Context, id xid.ID) (*GeofenceViolation, error)
func (*BunRepository) IsLocationTrusted ΒΆ
func (r *BunRepository) IsLocationTrusted(ctx context.Context, userID xid.ID, lat, lon float64) (bool, *TrustedLocation, error)
func (*BunRepository) ListEnabledRules ΒΆ
func (r *BunRepository) ListEnabledRules(ctx context.Context, appID xid.ID, userID *xid.ID) ([]*GeofenceRule, error)
func (*BunRepository) ResolveViolation ΒΆ
func (*BunRepository) SetCachedGeoData ΒΆ
func (r *BunRepository) SetCachedGeoData(ctx context.Context, cache *GeoCache) error
func (*BunRepository) UpdateRule ΒΆ
func (r *BunRepository) UpdateRule(ctx context.Context, rule *GeofenceRule) error
func (*BunRepository) UpdateTravelAlert ΒΆ
func (r *BunRepository) UpdateTravelAlert(ctx context.Context, alert *TravelAlert) error
func (*BunRepository) UpdateTrustedLocation ΒΆ
func (r *BunRepository) UpdateTrustedLocation(ctx context.Context, location *TrustedLocation) error
type CachedDetection ΒΆ
type CachedDetection struct {
Data *DetectionResult
ExpiresAt time.Time
}
CachedDetection represents cached detection data
type Config ΒΆ
type Config struct {
Enabled bool `json:"enabled" yaml:"enabled"`
// Geographic Restrictions
Restrictions RestrictionConfig `json:"restrictions" yaml:"restrictions"`
// IP Geolocation
Geolocation GeolocationConfig `json:"geolocation" yaml:"geolocation"`
// GPS-Based Authentication
GPS GPSConfig `json:"gps" yaml:"gps"`
// VPN/Proxy Detection
Detection DetectionConfig `json:"detection" yaml:"detection"`
// Corporate Network Detection
Corporate CorporateConfig `json:"corporate" yaml:"corporate"`
// Travel Notifications
Travel TravelConfig `json:"travel" yaml:"travel"`
// Session Management
Session SessionConfig `json:"session" yaml:"session"`
// API Endpoints
API APIConfig `json:"api" yaml:"api"`
// Security & Audit
Security SecurityConfig `json:"security" yaml:"security"`
// Session Security Notifications
Notifications NotificationConfig `json:"notifications" yaml:"notifications"`
}
Config holds the geofencing plugin configuration
func DefaultConfig ΒΆ
func DefaultConfig() *Config
DefaultConfig returns the default geofencing configuration
type CorporateConfig ΒΆ
type CorporateConfig struct {
Enabled bool `json:"enabled" yaml:"enabled"`
// Network Ranges
Networks []string `json:"networks" yaml:"networks"` // CIDR ranges
RequireNetwork bool `json:"requireNetwork" yaml:"requireNetwork"`
// DNS-Based Detection
RequiredDNS []string `json:"requiredDns" yaml:"requiredDns"` // Expected DNS servers
// Certificate-Based Detection
RequireCert bool `json:"requireCert" yaml:"requireCert"`
TrustedCerts []string `json:"trustedCerts" yaml:"trustedCerts"` // Cert fingerprints
// Hybrid Detection
AllowExternal bool `json:"allowExternal" yaml:"allowExternal"` // Allow external if other auth strong
RequireMFA bool `json:"requireMfa" yaml:"requireMfa"` // Require MFA for external
}
CorporateConfig configures corporate network detection
type DetectionConfig ΒΆ
type DetectionConfig struct {
// VPN Detection
DetectVPN bool `json:"detectVpn" yaml:"detectVpn"`
BlockVPN bool `json:"blockVpn" yaml:"blockVpn"`
AllowedVPNs []string `json:"allowedVpns" yaml:"allowedVpns"` // Whitelisted VPN providers
// Proxy Detection
DetectProxy bool `json:"detectProxy" yaml:"detectProxy"`
BlockProxy bool `json:"blockProxy" yaml:"blockProxy"`
AllowedProxies []string `json:"allowedProxies" yaml:"allowedProxies"`
// Tor Detection
DetectTor bool `json:"detectTor" yaml:"detectTor"`
BlockTor bool `json:"blockTor" yaml:"blockTor"`
// Datacenter Detection
DetectDatacenter bool `json:"detectDatacenter" yaml:"detectDatacenter"`
BlockDatacenter bool `json:"blockDatacenter" yaml:"blockDatacenter"`
// Detection Services
Provider string `json:"provider" yaml:"provider"` // ipqs, proxycheck, vpnapi
ProviderConfig map[string]string `json:"providerConfig" yaml:"providerConfig"`
// IPQualityScore
IPQSKey string `json:"ipqsKey" yaml:"ipqsKey"`
IPQSStrictness int `json:"ipqsStrictness" yaml:"ipqsStrictness"` // 0-3
IPQSMinScore float64 `json:"ipqsMinScore" yaml:"ipqsMinScore"` // 0-100
// ProxyCheck.io
ProxyCheckKey string `json:"proxycheckKey" yaml:"proxycheckKey"`
// VPNapi.io
VPNAPIKey string `json:"vpnapiKey" yaml:"vpnapiKey"`
// Caching
CacheDuration time.Duration `json:"cacheDuration" yaml:"cacheDuration"`
CacheMaxSize int `json:"cacheMaxSize" yaml:"cacheMaxSize"`
}
DetectionConfig configures VPN/proxy detection
type DetectionProvider ΒΆ
type DetectionProvider interface {
Check(ctx context.Context, ip string) (*DetectionResult, error)
Name() string
}
DetectionProvider defines the interface for VPN/Proxy/Tor detection
type DetectionResult ΒΆ
type DetectionResult struct {
IPAddress string
IsVPN bool
IsProxy bool
IsTor bool
IsDatacenter bool
VPNProvider string
FraudScore *float64
Provider string
}
DetectionResult represents VPN/proxy detection results
type ErrorResponse ΒΆ
type ErrorResponse = responses.ErrorResponse
Response types - use shared responses from core
type GPSConfig ΒΆ
type GPSConfig struct {
Enabled bool `json:"enabled" yaml:"enabled"`
// Coordinate Requirements
RequireGPS bool `json:"requireGps" yaml:"requireGps"`
MaxAccuracyMeters float64 `json:"maxAccuracyMeters" yaml:"maxAccuracyMeters"`
MinAccuracyMeters float64 `json:"minAccuracyMeters" yaml:"minAccuracyMeters"`
// Geofencing
Geofences []Geofence `json:"geofences" yaml:"geofences"`
RequireInsideFence bool `json:"requireInsideFence" yaml:"requireInsideFence"`
// Movement Detection
MaxSpeedKmh float64 `json:"maxSpeedKmh" yaml:"maxSpeedKmh"` // Alert on impossible travel speed
MinTimeBetween time.Duration `json:"minTimeBetween" yaml:"minTimeBetween"`
// Validation
ValidateTimestamp bool `json:"validateTimestamp" yaml:"validateTimestamp"`
MaxTimestampAge time.Duration `json:"maxTimestampAge" yaml:"maxTimestampAge"`
}
GPSConfig configures GPS-based authentication
type GPSData ΒΆ
type GPSData struct {
Latitude float64
Longitude float64
AccuracyMeters float64
Timestamp time.Time
}
GPSData represents GPS coordinates from a device
type GeoCache ΒΆ
type GeoCache struct {
bun.BaseModel `bun:"table:geo_cache,alias:gc"`
IPAddress string `bun:"ip_address,pk,notnull" json:"ipAddress"`
// Geolocation Data
Country string `bun:"country" json:"country"`
CountryCode string `bun:"country_code" json:"countryCode"`
Region string `bun:"region" json:"region"`
City string `bun:"city" json:"city"`
Latitude *float64 `bun:"latitude" json:"latitude,omitempty"`
Longitude *float64 `bun:"longitude" json:"longitude,omitempty"`
AccuracyKm *float64 `bun:"accuracy_km" json:"accuracyKm,omitempty"`
// Detection Data
IsVPN bool `bun:"is_vpn" json:"isVpn"`
IsProxy bool `bun:"is_proxy" json:"isProxy"`
IsTor bool `bun:"is_tor" json:"isTor"`
IsDatacenter bool `bun:"is_datacenter" json:"isDatacenter"`
VPNProvider string `bun:"vpn_provider" json:"vpnProvider,omitempty"`
FraudScore *float64 `bun:"fraud_score" json:"fraudScore,omitempty"`
// Network Info
ASN string `bun:"asn" json:"asn,omitempty"`
ISP string `bun:"isp" json:"isp,omitempty"`
Organization string `bun:"organization" json:"organization,omitempty"`
// Cache Metadata
Provider string `bun:"provider,notnull" json:"provider"` // Which provider gave us this data
CachedAt time.Time `bun:"cached_at,notnull,default:current_timestamp" json:"cachedAt"`
ExpiresAt time.Time `bun:"expires_at,notnull" json:"expiresAt"`
HitCount int `bun:"hit_count" json:"hitCount"`
}
GeoCache represents cached geolocation data
type GeoData ΒΆ
type GeoData struct {
IPAddress string
Country string
CountryCode string // ISO 3166-1 alpha-2
Region string
City string
Latitude *float64
Longitude *float64
AccuracyKm *float64
ASN string
ISP string
Organization string
Provider string
}
GeoData represents geolocation information
type GeoProvider ΒΆ
type GeoProvider interface {
Lookup(ctx context.Context, ip string) (*GeoData, error)
Name() string
}
GeoProvider defines the interface for geolocation providers
type Geofence ΒΆ
type Geofence struct {
ID string `json:"id" yaml:"id"`
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
Type string `json:"type" yaml:"type"` // "circle", "polygon"
// Circle
CenterLat float64 `json:"centerLat" yaml:"centerLat"`
CenterLon float64 `json:"centerLon" yaml:"centerLon"`
RadiusKm float64 `json:"radiusKm" yaml:"radiusKm"`
// Polygon (array of [lat, lon] pairs)
Coordinates [][2]float64 `json:"coordinates" yaml:"coordinates"`
// Rules
Action string `json:"action" yaml:"action"` // "allow" or "deny"
Users []string `json:"users" yaml:"users"` // Specific user IDs (empty = all)
Roles []string `json:"roles" yaml:"roles"` // Specific roles (empty = all)
}
Geofence defines a geographic boundary
type GeofenceCheckResponse ΒΆ
type GeofenceErrorResponse ΒΆ
type GeofenceErrorResponse struct {
Error string `json:"error" example:"Error message"`
}
DTOs for geofence routes
type GeofenceEventResponse ΒΆ
type GeofenceEventResponse struct {
ID string `json:"id" example:"event_123"`
}
type GeofenceEventsResponse ΒΆ
type GeofenceEventsResponse struct {
Events []interface{} `json:"events"`
}
type GeofenceLocationAnalyticsResponse ΒΆ
type GeofenceLocationAnalyticsResponse struct {
Analytics interface{} `json:"analytics"`
}
type GeofenceLookupResponse ΒΆ
type GeofenceMetricsResponse ΒΆ
type GeofenceMetricsResponse struct {
Metrics interface{} `json:"metrics"`
}
type GeofenceRule ΒΆ
type GeofenceRule struct {
bun.BaseModel `bun:"table:geofence_rules,alias:gr"`
ID xid.ID `bun:"id,pk,type:varchar(20)" json:"id"`
AppID xid.ID `bun:"app_id,type:varchar(20),notnull" json:"appId"`
UserID *xid.ID `bun:"user_id,type:varchar(20)" json:"userId,omitempty"` // Null = app-wide
Name string `bun:"name,notnull" json:"name"`
Description string `bun:"description" json:"description"`
Enabled bool `bun:"enabled,notnull" json:"enabled"`
Priority int `bun:"priority,notnull" json:"priority"` // Higher = evaluated first
// Rule Type
RuleType string `bun:"rule_type,notnull" json:"ruleType"` // country, region, city, geofence, distance
// Geographic Criteria (JSON)
AllowedCountries []string `bun:"allowed_countries,type:jsonb" json:"allowedCountries,omitempty"`
BlockedCountries []string `bun:"blocked_countries,type:jsonb" json:"blockedCountries,omitempty"`
AllowedRegions []string `bun:"allowed_regions,type:jsonb" json:"allowedRegions,omitempty"`
BlockedRegions []string `bun:"blocked_regions,type:jsonb" json:"blockedRegions,omitempty"`
AllowedCities []string `bun:"allowed_cities,type:jsonb" json:"allowedCities,omitempty"`
BlockedCities []string `bun:"blocked_cities,type:jsonb" json:"blockedCities,omitempty"`
// Geofence Data (JSON)
GeofenceType string `bun:"geofence_type" json:"geofenceType,omitempty"` // circle, polygon
CenterLat *float64 `bun:"center_lat" json:"centerLat,omitempty"`
CenterLon *float64 `bun:"center_lon" json:"centerLon,omitempty"`
RadiusKm *float64 `bun:"radius_km" json:"radiusKm,omitempty"`
Coordinates [][2]float64 `bun:"coordinates,type:jsonb" json:"coordinates,omitempty"`
// Distance Restrictions
MaxDistanceKm *float64 `bun:"max_distance_km" json:"maxDistanceKm,omitempty"`
ReferencePoint *[2]float64 `bun:"reference_point,type:jsonb" json:"referencePoint,omitempty"` // [lat, lon]
// Time Restrictions (JSON)
TimeRestrictions []TimeRestrictionRule `bun:"time_restrictions,type:jsonb" json:"timeRestrictions,omitempty"`
// Detection Settings
BlockVPN bool `bun:"block_vpn" json:"blockVpn"`
BlockProxy bool `bun:"block_proxy" json:"blockProxy"`
BlockTor bool `bun:"block_tor" json:"blockTor"`
BlockDatacenter bool `bun:"block_datacenter" json:"blockDatacenter"`
// Actions
Action string `bun:"action,notnull" json:"action"` // allow, deny, mfa_required, notify
RequireMFA bool `bun:"require_mfa" json:"requireMfa"`
NotifyUser bool `bun:"notify_user" json:"notifyUser"`
NotifyAdmin bool `bun:"notify_admin" json:"notifyAdmin"`
// Metadata
CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp" json:"createdAt"`
UpdatedAt time.Time `bun:"updated_at,notnull,default:current_timestamp" json:"updatedAt"`
CreatedBy xid.ID `bun:"created_by,type:varchar(20)" json:"createdBy"`
UpdatedBy *xid.ID `bun:"updated_by,type:varchar(20)" json:"updatedBy,omitempty"`
}
GeofenceRule represents a geographic restriction rule
type GeofenceRuleResponse ΒΆ
type GeofenceRuleResponse struct {
ID string `json:"id" example:"rule_123"`
}
type GeofenceRulesResponse ΒΆ
type GeofenceRulesResponse struct {
Rules []interface{} `json:"rules"`
}
type GeofenceStatusResponse ΒΆ
type GeofenceStatusResponse struct {
Status string `json:"status" example:"success"`
}
type GeofenceTravelAlertResponse ΒΆ
type GeofenceTravelAlertResponse struct {
ID string `json:"id" example:"alert_123"`
}
type GeofenceTravelAlertsResponse ΒΆ
type GeofenceTravelAlertsResponse struct {
TravelAlerts []interface{} `json:"travel_alerts"`
}
type GeofenceTrustedLocationResponse ΒΆ
type GeofenceTrustedLocationResponse struct {
ID string `json:"id" example:"trusted_123"`
}
type GeofenceTrustedLocationsResponse ΒΆ
type GeofenceTrustedLocationsResponse struct {
TrustedLocations []interface{} `json:"trusted_locations"`
}
type GeofenceViolation ΒΆ
type GeofenceViolation struct {
bun.BaseModel `bun:"table:geofence_violations,alias:gv"`
ID xid.ID `bun:"id,pk,type:varchar(20)" json:"id"`
UserID xid.ID `bun:"user_id,type:varchar(20),notnull" json:"userId"`
AppID xid.ID `bun:"app_id,type:varchar(20),notnull" json:"appId"`
RuleID xid.ID `bun:"rule_id,type:varchar(20),notnull" json:"ruleId"`
// Violation Details
ViolationType string `bun:"violation_type,notnull" json:"violationType"` // blocked_country, vpn_detected, etc.
Severity string `bun:"severity,notnull" json:"severity"` // low, medium, high, critical
Action string `bun:"action,notnull" json:"action"` // blocked, flagged, mfa_required
// Location Context
IPAddress string `bun:"ip_address,notnull" json:"ipAddress"`
Country string `bun:"country" json:"country"`
CountryCode string `bun:"country_code" json:"countryCode"`
City string `bun:"city" json:"city"`
Latitude *float64 `bun:"latitude" json:"latitude,omitempty"`
Longitude *float64 `bun:"longitude" json:"longitude,omitempty"`
// Detection Info
IsVPN bool `bun:"is_vpn" json:"isVpn"`
IsProxy bool `bun:"is_proxy" json:"isProxy"`
IsTor bool `bun:"is_tor" json:"isTor"`
IsDatacenter bool `bun:"is_datacenter" json:"isDatacenter"`
// Response
Blocked bool `bun:"blocked" json:"blocked"`
UserNotified bool `bun:"user_notified" json:"userNotified"`
AdminNotified bool `bun:"admin_notified" json:"adminNotified"`
// Resolution
Resolved bool `bun:"resolved" json:"resolved"`
ResolvedAt *time.Time `bun:"resolved_at" json:"resolvedAt,omitempty"`
ResolvedBy *xid.ID `bun:"resolved_by,type:varchar(20)" json:"resolvedBy,omitempty"`
Resolution string `bun:"resolution" json:"resolution,omitempty"`
// References
LocationEventID *xid.ID `bun:"location_event_id,type:varchar(20)" json:"locationEventId,omitempty"`
SessionID *xid.ID `bun:"session_id,type:varchar(20)" json:"sessionId,omitempty"`
// Metadata
CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp" json:"createdAt"`
UpdatedAt time.Time `bun:"updated_at,notnull,default:current_timestamp" json:"updatedAt"`
Metadata map[string]interface{} `bun:"metadata,type:jsonb" json:"metadata,omitempty"`
}
GeofenceViolation represents a geofence policy violation
type GeofenceViolationAnalyticsResponse ΒΆ
type GeofenceViolationAnalyticsResponse struct {
Analytics interface{} `json:"analytics"`
}
type GeofenceViolationResponse ΒΆ
type GeofenceViolationResponse struct {
ID string `json:"id" example:"violation_123"`
}
type GeofenceViolationsResponse ΒΆ
type GeofenceViolationsResponse struct {
Violations []interface{} `json:"violations"`
}
type GeolocationConfig ΒΆ
type GeolocationConfig struct {
// Primary Provider
Provider string `json:"provider" yaml:"provider"` // maxmind, ipapi, ipinfo, ipgeolocation
ProviderConfig map[string]string `json:"providerConfig" yaml:"providerConfig"`
FallbackProvider string `json:"fallbackProvider" yaml:"fallbackProvider"`
// MaxMind GeoIP2
MaxMindLicenseKey string `json:"maxmindLicenseKey" yaml:"maxmindLicenseKey"`
MaxMindDatabasePath string `json:"maxmindDatabasePath" yaml:"maxmindDatabasePath"`
MaxMindAutoUpdate bool `json:"maxmindAutoUpdate" yaml:"maxmindAutoUpdate"`
// IPInfo.io
IPInfoToken string `json:"ipinfoToken" yaml:"ipinfoToken"`
// ipapi.com
IPAPIKey string `json:"ipapiKey" yaml:"ipapiKey"`
// ipgeolocation.io
IPGeolocationKey string `json:"ipgeolocationKey" yaml:"ipgeolocationKey"`
// Caching
CacheDuration time.Duration `json:"cacheDuration" yaml:"cacheDuration"`
CacheMaxSize int `json:"cacheMaxSize" yaml:"cacheMaxSize"`
// Performance
Timeout time.Duration `json:"timeout" yaml:"timeout"`
MaxRetries int `json:"maxRetries" yaml:"maxRetries"`
// Accuracy Requirements
MinAccuracyKm float64 `json:"minAccuracyKm" yaml:"minAccuracyKm"` // Minimum accuracy in km
}
GeolocationConfig configures IP geolocation services
type Handler ΒΆ
type Handler struct {
// contains filtered or unexported fields
}
Handler handles HTTP requests for geofencing
func NewHandler ΒΆ
NewHandler creates a new geofencing handler
func (*Handler) ApproveTravelAlert ΒΆ
ApproveTravelAlert approves a travel alert
func (*Handler) CheckLocation ΒΆ
CheckLocation performs a geofence check
func (*Handler) CreateRule ΒΆ
CreateRule creates a new geofence rule
func (*Handler) CreateTrustedLocation ΒΆ
CreateTrustedLocation creates a trusted location
func (*Handler) DeleteRule ΒΆ
DeleteRule deletes a geofence rule
func (*Handler) DeleteTrustedLocation ΒΆ
DeleteTrustedLocation deletes a trusted location
func (*Handler) DenyTravelAlert ΒΆ
DenyTravelAlert denies a travel alert
func (*Handler) GetLocationAnalytics ΒΆ
GetLocationAnalytics returns location analytics
func (*Handler) GetLocationEvent ΒΆ
GetLocationEvent gets a specific location event
func (*Handler) GetMetrics ΒΆ
GetMetrics returns geofencing metrics
func (*Handler) GetTravelAlert ΒΆ
GetTravelAlert gets a specific travel alert
func (*Handler) GetTrustedLocation ΒΆ
GetTrustedLocation gets a specific trusted location
func (*Handler) GetViolation ΒΆ
GetViolation gets a specific violation
func (*Handler) GetViolationAnalytics ΒΆ
GetViolationAnalytics returns violation analytics
func (*Handler) ListLocationEvents ΒΆ
ListLocationEvents lists location events for the authenticated user
func (*Handler) ListTravelAlerts ΒΆ
ListTravelAlerts lists travel alerts for the authenticated user
func (*Handler) ListTrustedLocations ΒΆ
ListTrustedLocations lists trusted locations for the authenticated user
func (*Handler) ListViolations ΒΆ
ListViolations lists geofence violations
func (*Handler) ResolveViolation ΒΆ
ResolveViolation resolves a geofence violation
func (*Handler) UpdateRule ΒΆ
UpdateRule updates a geofence rule
type IPAPIProvider ΒΆ
type IPAPIProvider struct {
// contains filtered or unexported fields
}
IPAPIProvider implements GeoProvider using ipapi.com
func NewIPAPIProvider ΒΆ
func NewIPAPIProvider(apiKey string) *IPAPIProvider
NewIPAPIProvider creates a new ipapi.com provider
func (*IPAPIProvider) Name ΒΆ
func (p *IPAPIProvider) Name() string
type IPGeolocationProvider ΒΆ
type IPGeolocationProvider struct {
// contains filtered or unexported fields
}
IPGeolocationProvider implements GeoProvider using ipgeolocation.io
func NewIPGeolocationProvider ΒΆ
func NewIPGeolocationProvider(apiKey string) *IPGeolocationProvider
NewIPGeolocationProvider creates a new ipgeolocation.io provider
func (*IPGeolocationProvider) Name ΒΆ
func (p *IPGeolocationProvider) Name() string
type IPInfoProvider ΒΆ
type IPInfoProvider struct {
// contains filtered or unexported fields
}
IPInfoProvider implements GeoProvider using ipinfo.io
func NewIPInfoProvider ΒΆ
func NewIPInfoProvider(token string) *IPInfoProvider
NewIPInfoProvider creates a new ipinfo.io provider
func (*IPInfoProvider) Name ΒΆ
func (p *IPInfoProvider) Name() string
type IPQSProvider ΒΆ
type IPQSProvider struct {
// contains filtered or unexported fields
}
IPQSProvider implements DetectionProvider using IPQualityScore
func NewIPQSProvider ΒΆ
func NewIPQSProvider(apiKey string, strictness int, minScore float64) *IPQSProvider
NewIPQSProvider creates a new IPQualityScore provider
func (*IPQSProvider) Check ΒΆ
func (p *IPQSProvider) Check(ctx context.Context, ip string) (*DetectionResult, error)
func (*IPQSProvider) Name ΒΆ
func (p *IPQSProvider) Name() string
type LocationCheckRequest ΒΆ
type LocationCheckRequest struct {
UserID xid.ID
AppID xid.ID
SessionID *xid.ID
IPAddress string
UserAgent string
EventType string // "login", "request", "manual_check"
GPS *GPSData
}
LocationCheckRequest represents a geofence check request
type LocationCheckResult ΒΆ
type LocationCheckResult struct {
Allowed bool
Reason string
RuleName string
RequireMFA bool
Notify bool
Violations []string
TravelAlert bool
TravelAlertID *xid.ID
}
LocationCheckResult represents the result of a geofence check
type LocationEvent ΒΆ
type LocationEvent struct {
bun.BaseModel `bun:"table:location_events,alias:le"`
ID xid.ID `bun:"id,pk,type:varchar(20)" json:"id"`
UserID xid.ID `bun:"user_id,type:varchar(20),notnull" json:"userId"`
AppID xid.ID `bun:"app_id,type:varchar(20),notnull" json:"appId"`
SessionID *xid.ID `bun:"session_id,type:varchar(20)" json:"sessionId,omitempty"`
// Location Data
IPAddress string `bun:"ip_address,notnull" json:"ipAddress"`
Country string `bun:"country" json:"country"`
CountryCode string `bun:"country_code" json:"countryCode"` // ISO 3166-1 alpha-2
Region string `bun:"region" json:"region"`
City string `bun:"city" json:"city"`
Latitude *float64 `bun:"latitude" json:"latitude,omitempty"`
Longitude *float64 `bun:"longitude" json:"longitude,omitempty"`
AccuracyKm *float64 `bun:"accuracy_km" json:"accuracyKm,omitempty"`
// GPS Data (if available)
GPSLatitude *float64 `bun:"gps_latitude" json:"gpsLatitude,omitempty"`
GPSLongitude *float64 `bun:"gps_longitude" json:"gpsLongitude,omitempty"`
GPSAccuracy *float64 `bun:"gps_accuracy" json:"gpsAccuracy,omitempty"` // meters
GPSTimestamp *time.Time `bun:"gps_timestamp" json:"gpsTimestamp,omitempty"`
// Detection Results
IsVPN bool `bun:"is_vpn" json:"isVpn"`
IsProxy bool `bun:"is_proxy" json:"isProxy"`
IsTor bool `bun:"is_tor" json:"isTor"`
IsDatacenter bool `bun:"is_datacenter" json:"isDatacenter"`
VPNProvider string `bun:"vpn_provider" json:"vpnProvider,omitempty"`
FraudScore *float64 `bun:"fraud_score" json:"fraudScore,omitempty"`
// Network Info
ASN string `bun:"asn" json:"asn,omitempty"`
ISP string `bun:"isp" json:"isp,omitempty"`
Organization string `bun:"organization" json:"organization,omitempty"`
ConnectionType string `bun:"connection_type" json:"connectionType,omitempty"` // cable, cellular, etc.
// Context
UserAgent string `bun:"user_agent" json:"userAgent,omitempty"`
EventType string `bun:"event_type,notnull" json:"eventType"` // login, request, manual_check
EventResult string `bun:"event_result,notnull" json:"eventResult"` // allowed, denied, flagged
RuleName string `bun:"rule_name" json:"ruleName,omitempty"` // Which rule triggered
// Distance from previous location
DistanceKm *float64 `bun:"distance_km" json:"distanceKm,omitempty"`
TimeFromPrev *time.Duration `bun:"time_from_prev" json:"timeFromPrev,omitempty"`
SpeedKmh *float64 `bun:"speed_kmh" json:"speedKmh,omitempty"` // Calculated speed
// Metadata
Timestamp time.Time `bun:"timestamp,notnull,default:current_timestamp" json:"timestamp"`
Metadata map[string]interface{} `bun:"metadata,type:jsonb" json:"metadata,omitempty"`
}
LocationEvent represents a recorded location event
type MaxMindProvider ΒΆ
type MaxMindProvider struct {
// contains filtered or unexported fields
}
MaxMindProvider implements GeoProvider using MaxMind GeoIP2
func NewMaxMindProvider ΒΆ
func NewMaxMindProvider(licenseKey, databasePath string) *MaxMindProvider
NewMaxMindProvider creates a new MaxMind provider
func (*MaxMindProvider) Name ΒΆ
func (p *MaxMindProvider) Name() string
type MessageResponse ΒΆ
type MessageResponse = responses.MessageResponse
type Middleware ΒΆ
type Middleware struct {
// contains filtered or unexported fields
}
Middleware provides geofence checking middleware
func NewMiddleware ΒΆ
func NewMiddleware(service *Service, config *Config) *Middleware
NewMiddleware creates a new geofence middleware
func (*Middleware) BlockProxy ΒΆ
BlockProxy middleware blocks requests from proxies
func (*Middleware) CheckGeofence ΒΆ
CheckGeofence middleware checks geofence rules for each request
func (*Middleware) RequireCountry ΒΆ
func (m *Middleware) RequireCountry(countries ...string) func(next func(forge.Context) error) func(forge.Context) error
RequireCountry middleware requires the request to come from specific countries
func (*Middleware) RequireLocation ΒΆ
RequireLocation middleware requires geofence check to pass This is a stronger enforcement than CheckGeofence
type NotificationConfig ΒΆ added in v0.0.6
type NotificationConfig struct {
// General
Enabled bool `json:"enabled" yaml:"enabled"`
// New Location Notifications
NewLocationEnabled bool `json:"newLocationEnabled" yaml:"newLocationEnabled"`
NewLocationThresholdKm float64 `json:"newLocationThresholdKm" yaml:"newLocationThresholdKm"` // Trigger at N km distance
// Suspicious Login Notifications
SuspiciousLoginEnabled bool `json:"suspiciousLoginEnabled" yaml:"suspiciousLoginEnabled"`
SuspiciousLoginScoreThreshold float64 `json:"suspiciousLoginScoreThreshold" yaml:"suspiciousLoginScoreThreshold"` // IPQS fraud score threshold
// Detection Types
ImpossibleTravelEnabled bool `json:"impossibleTravelEnabled" yaml:"impossibleTravelEnabled"`
VpnDetectionEnabled bool `json:"vpnDetectionEnabled" yaml:"vpnDetectionEnabled"`
ProxyDetectionEnabled bool `json:"proxyDetectionEnabled" yaml:"proxyDetectionEnabled"`
TorDetectionEnabled bool `json:"torDetectionEnabled" yaml:"torDetectionEnabled"`
}
NotificationConfig configures session security notifications
type Plugin ΒΆ
type Plugin struct {
// contains filtered or unexported fields
}
Plugin implements the AuthSome plugin interface for geofencing
func (*Plugin) Description ΒΆ
Description returns the plugin description
func (*Plugin) Middleware ΒΆ
Middleware returns the geofence middleware for automatic checks
func (*Plugin) RegisterHooks ΒΆ
func (p *Plugin) RegisterHooks(hookRegistry *hooks.HookRegistry) error
RegisterHooks registers plugin hooks with the hook registry
func (*Plugin) RegisterRoutes ΒΆ
RegisterRoutes registers HTTP routes for the plugin
func (*Plugin) RegisterServiceDecorators ΒΆ
func (p *Plugin) RegisterServiceDecorators(services *registry.ServiceRegistry) error
RegisterServiceDecorators allows plugins to replace core services with decorated versions
type ProxyCheckProvider ΒΆ
type ProxyCheckProvider struct {
// contains filtered or unexported fields
}
ProxyCheckProvider implements DetectionProvider using proxycheck.io
func NewProxyCheckProvider ΒΆ
func NewProxyCheckProvider(apiKey string) *ProxyCheckProvider
NewProxyCheckProvider creates a new proxycheck.io provider
func (*ProxyCheckProvider) Check ΒΆ
func (p *ProxyCheckProvider) Check(ctx context.Context, ip string) (*DetectionResult, error)
func (*ProxyCheckProvider) Name ΒΆ
func (p *ProxyCheckProvider) Name() string
type Repository ΒΆ
type Repository interface {
// Rules
CreateRule(ctx context.Context, rule *GeofenceRule) error
GetRule(ctx context.Context, id xid.ID) (*GeofenceRule, error)
GetRulesByApp(ctx context.Context, appID xid.ID) ([]*GeofenceRule, error)
GetRulesByUser(ctx context.Context, userID xid.ID) ([]*GeofenceRule, error)
UpdateRule(ctx context.Context, rule *GeofenceRule) error
DeleteRule(ctx context.Context, id xid.ID) error
ListEnabledRules(ctx context.Context, appID xid.ID, userID *xid.ID) ([]*GeofenceRule, error)
// Location Events
CreateLocationEvent(ctx context.Context, event *LocationEvent) error
GetLocationEvent(ctx context.Context, id xid.ID) (*LocationEvent, error)
GetUserLocationHistory(ctx context.Context, userID xid.ID, limit int) ([]*LocationEvent, error)
GetLastLocationEvent(ctx context.Context, userID xid.ID) (*LocationEvent, error)
GetLastLocation(ctx context.Context, userID xid.ID, appID xid.ID) (*GeoData, error)
DeleteOldLocationEvents(ctx context.Context, before time.Time) (int64, error)
// Travel Alerts
CreateTravelAlert(ctx context.Context, alert *TravelAlert) error
GetTravelAlert(ctx context.Context, id xid.ID) (*TravelAlert, error)
GetUserTravelAlerts(ctx context.Context, userID xid.ID, status string) ([]*TravelAlert, error)
GetPendingTravelAlerts(ctx context.Context, appID xid.ID) ([]*TravelAlert, error)
UpdateTravelAlert(ctx context.Context, alert *TravelAlert) error
ApproveTravel(ctx context.Context, alertID xid.ID, approvedBy xid.ID) error
DenyTravel(ctx context.Context, alertID xid.ID, deniedBy xid.ID) error
// Trusted Locations
CreateTrustedLocation(ctx context.Context, location *TrustedLocation) error
GetTrustedLocation(ctx context.Context, id xid.ID) (*TrustedLocation, error)
GetUserTrustedLocations(ctx context.Context, userID xid.ID) ([]*TrustedLocation, error)
UpdateTrustedLocation(ctx context.Context, location *TrustedLocation) error
DeleteTrustedLocation(ctx context.Context, id xid.ID) error
IsLocationTrusted(ctx context.Context, userID xid.ID, lat, lon float64) (bool, *TrustedLocation, error)
// Violations
CreateViolation(ctx context.Context, violation *GeofenceViolation) error
GetViolation(ctx context.Context, id xid.ID) (*GeofenceViolation, error)
GetUserViolations(ctx context.Context, userID xid.ID, limit int) ([]*GeofenceViolation, error)
GetAppViolations(ctx context.Context, appID xid.ID, limit int) ([]*GeofenceViolation, error)
GetUnresolvedViolations(ctx context.Context, appID xid.ID) ([]*GeofenceViolation, error)
ResolveViolation(ctx context.Context, id xid.ID, resolvedBy xid.ID, resolution string) error
// Geo Cache
GetCachedGeoData(ctx context.Context, ip string) (*GeoCache, error)
SetCachedGeoData(ctx context.Context, cache *GeoCache) error
DeleteExpiredCache(ctx context.Context) (int64, error)
}
Repository defines the interface for geofence data storage
func NewBunRepository ΒΆ
func NewBunRepository(db *bun.DB) Repository
NewBunRepository creates a new Bun-based repository
type RestrictionConfig ΒΆ
type RestrictionConfig struct {
// Country/Region Controls
AllowedCountries []string `json:"allowedCountries" yaml:"allowedCountries"` // ISO 3166-1 alpha-2
BlockedCountries []string `json:"blockedCountries" yaml:"blockedCountries"` // ISO 3166-1 alpha-2
AllowedRegions []string `json:"allowedRegions" yaml:"allowedRegions"` // US: state codes, etc.
BlockedRegions []string `json:"blockedRegions" yaml:"blockedRegions"`
// City-Level Controls
AllowedCities []string `json:"allowedCities" yaml:"allowedCities"`
BlockedCities []string `json:"blockedCities" yaml:"blockedCities"`
// Time-Based Restrictions
TimeRestrictions []TimeRestriction `json:"timeRestrictions" yaml:"timeRestrictions"`
// Distance-Based Restrictions
MaxDistanceKm float64 `json:"maxDistanceKm" yaml:"maxDistanceKm"` // Max distance from reference point
// Behavior
DefaultAction string `json:"defaultAction" yaml:"defaultAction"` // "allow" or "deny"
StrictMode bool `json:"strictMode" yaml:"strictMode"` // Deny on lookup failure
}
RestrictionConfig configures geographic restrictions
type RulesResponse ΒΆ
type RulesResponse struct {
Rules interface{} `json:"rules"`
Count int `json:"count"`
}
type SecurityConfig ΒΆ
type SecurityConfig struct {
// Rate Limiting
RateLimitEnabled bool `json:"rateLimitEnabled" yaml:"rateLimitEnabled"`
MaxChecksPerMinute int `json:"maxChecksPerMinute" yaml:"maxChecksPerMinute"`
MaxChecksPerHour int `json:"maxChecksPerHour" yaml:"maxChecksPerHour"`
// Audit Logging
AuditAllChecks bool `json:"auditAllChecks" yaml:"auditAllChecks"`
AuditViolations bool `json:"auditViolations" yaml:"auditViolations"`
AuditTravel bool `json:"auditTravel" yaml:"auditTravel"`
// Data Storage
StoreLocations bool `json:"storeLocations" yaml:"storeLocations"`
LocationRetention time.Duration `json:"locationRetention" yaml:"locationRetention"`
AnonymizeOldData bool `json:"anonymizeOldData" yaml:"anonymizeOldData"`
// Privacy
ConsentRequired bool `json:"consentRequired" yaml:"consentRequired"`
AllowOptOut bool `json:"allowOptOut" yaml:"allowOptOut"`
// Notifications
NotifyOnViolation bool `json:"notifyOnViolation" yaml:"notifyOnViolation"`
NotifyOnAnomaly bool `json:"notifyOnAnomaly" yaml:"notifyOnAnomaly"`
}
SecurityConfig configures security settings
type Service ΒΆ
type Service struct {
// contains filtered or unexported fields
}
Service handles geofencing operations
func NewService ΒΆ
func NewService( config *Config, repo Repository, geoProvider GeoProvider, detectionProvider DetectionProvider, auditService *audit.Service, notificationService *notification.Service, authInst interface{}, ) *Service
NewService creates a new geofencing service
func (*Service) CheckLocation ΒΆ
func (s *Service) CheckLocation(ctx context.Context, req *LocationCheckRequest) (*LocationCheckResult, error)
CheckLocation performs a comprehensive geofence check
func (*Service) CheckSessionSecurity ΒΆ added in v0.0.6
func (s *Service) CheckSessionSecurity(ctx context.Context, userID xid.ID, appID xid.ID, ipAddress string) error
CheckSessionSecurity performs location and security checks for a session
func (*Service) GetDetection ΒΆ
GetDetection gets VPN/proxy detection data for an IP address
type SessionConfig ΒΆ
type SessionConfig struct {
// Location Tracking
TrackLocation bool `json:"trackLocation" yaml:"trackLocation"`
UpdateInterval time.Duration `json:"updateInterval" yaml:"updateInterval"`
// Session Validation
ValidateOnRequest bool `json:"validateOnRequest" yaml:"validateOnRequest"`
InvalidateOnViolation bool `json:"invalidateOnViolation" yaml:"invalidateOnViolation"`
// Grace Period
GracePeriod time.Duration `json:"gracePeriod" yaml:"gracePeriod"` // Allow brief violations
MaxViolations int `json:"maxViolations" yaml:"maxViolations"`
}
SessionConfig configures geofence session management
type StaticDetectionProvider ΒΆ
type StaticDetectionProvider struct {
// contains filtered or unexported fields
}
StaticDetectionProvider implements a simple rule-based detection Useful for testing or when external APIs are not available
func NewStaticDetectionProvider ΒΆ
func NewStaticDetectionProvider() *StaticDetectionProvider
NewStaticDetectionProvider creates a new static detection provider
func (*StaticDetectionProvider) AddDatacenter ΒΆ
func (p *StaticDetectionProvider) AddDatacenter(ip string)
AddDatacenter marks an IP as datacenter
func (*StaticDetectionProvider) AddProxy ΒΆ
func (p *StaticDetectionProvider) AddProxy(ip string)
AddProxy marks an IP as a proxy
func (*StaticDetectionProvider) AddTor ΒΆ
func (p *StaticDetectionProvider) AddTor(ip string)
AddTor marks an IP as Tor
func (*StaticDetectionProvider) AddVPN ΒΆ
func (p *StaticDetectionProvider) AddVPN(ip string)
AddVPN marks an IP as a VPN
func (*StaticDetectionProvider) Check ΒΆ
func (p *StaticDetectionProvider) Check(ctx context.Context, ip string) (*DetectionResult, error)
func (*StaticDetectionProvider) Name ΒΆ
func (p *StaticDetectionProvider) Name() string
type StatusResponse ΒΆ
type StatusResponse = responses.StatusResponse
type SuccessResponse ΒΆ
type SuccessResponse = responses.SuccessResponse
type TimeRestriction ΒΆ
type TimeRestriction struct {
Countries []string `json:"countries" yaml:"countries"`
AllowedDays []string `json:"allowedDays" yaml:"allowedDays"` // Monday, Tuesday, etc.
StartHour int `json:"startHour" yaml:"startHour"` // 0-23
EndHour int `json:"endHour" yaml:"endHour"` // 0-23
Timezone string `json:"timezone" yaml:"timezone"` // IANA timezone
}
TimeRestriction defines time-based access rules
type TimeRestrictionRule ΒΆ
type TimeRestrictionRule struct {
AllowedDays []string `json:"allowedDays"` // Monday, Tuesday, etc.
StartHour int `json:"startHour"` // 0-23
EndHour int `json:"endHour"` // 0-23
Timezone string `json:"timezone"` // IANA timezone
}
TimeRestrictionRule defines time-based access rules
type TravelAlert ΒΆ
type TravelAlert struct {
bun.BaseModel `bun:"table:travel_alerts,alias:ta"`
ID xid.ID `bun:"id,pk,type:varchar(20)" json:"id"`
UserID xid.ID `bun:"user_id,type:varchar(20),notnull" json:"userId"`
AppID xid.ID `bun:"app_id,type:varchar(20),notnull" json:"appId"`
// Alert Type
AlertType string `bun:"alert_type,notnull" json:"alertType"` // impossible_travel, new_location, anomaly
Severity string `bun:"severity,notnull" json:"severity"` // low, medium, high, critical
// Location Context
FromCountry string `bun:"from_country" json:"fromCountry"`
FromCity string `bun:"from_city" json:"fromCity"`
FromLat *float64 `bun:"from_lat" json:"fromLat,omitempty"`
FromLon *float64 `bun:"from_lon" json:"fromLon,omitempty"`
ToCountry string `bun:"to_country" json:"toCountry"`
ToCity string `bun:"to_city" json:"toCity"`
ToLat *float64 `bun:"to_lat" json:"toLat,omitempty"`
ToLon *float64 `bun:"to_lon" json:"toLon,omitempty"`
// Travel Metrics
DistanceKm float64 `bun:"distance_km,notnull" json:"distanceKm"`
TimeDifference time.Duration `bun:"time_difference,notnull" json:"timeDifference"`
CalculatedSpeed float64 `bun:"calculated_speed,notnull" json:"calculatedSpeed"` // km/h
// Status
Status string `bun:"status,notnull" json:"status"` // pending, approved, denied, auto_approved
RequiresApproval bool `bun:"requires_approval" json:"requiresApproval"`
ApprovedBy *xid.ID `bun:"approved_by,type:varchar(20)" json:"approvedBy,omitempty"`
ApprovedAt *time.Time `bun:"approved_at" json:"approvedAt,omitempty"`
// Notifications
UserNotified bool `bun:"user_notified" json:"userNotified"`
AdminNotified bool `bun:"admin_notified" json:"adminNotified"`
NotifiedAt *time.Time `bun:"notified_at" json:"notifiedAt,omitempty"`
// Resolution
ResolvedAt *time.Time `bun:"resolved_at" json:"resolvedAt,omitempty"`
Resolution string `bun:"resolution" json:"resolution,omitempty"`
// References
LocationEventID xid.ID `bun:"location_event_id,type:varchar(20)" json:"locationEventId"`
// Metadata
CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp" json:"createdAt"`
UpdatedAt time.Time `bun:"updated_at,notnull,default:current_timestamp" json:"updatedAt"`
Metadata map[string]interface{} `bun:"metadata,type:jsonb" json:"metadata,omitempty"`
}
TravelAlert represents a travel notification/alert
type TravelConfig ΒΆ
type TravelConfig struct {
Enabled bool `json:"enabled" yaml:"enabled"`
// Detection Thresholds
MinDistanceKm float64 `json:"minDistanceKm" yaml:"minDistanceKm"` // Trigger distance
MinTimeBetween time.Duration `json:"minTimeBetween" yaml:"minTimeBetween"` // Minimum time between locations
MaxSpeedKmh float64 `json:"maxSpeedKmh" yaml:"maxSpeedKmh"` // Impossible travel speed
// Notification Settings
NotifyUser bool `json:"notifyUser" yaml:"notifyUser"`
NotifyAdmin bool `json:"notifyAdmin" yaml:"notifyAdmin"`
RequireApproval bool `json:"requireApproval" yaml:"requireApproval"` // Block until approved
ApprovalTimeout time.Duration `json:"approvalTimeout" yaml:"approvalTimeout"`
// Channels
EmailNotify bool `json:"emailNotify" yaml:"emailNotify"`
SMSNotify bool `json:"smsNotify" yaml:"smsNotify"`
PushNotify bool `json:"pushNotify" yaml:"pushNotify"`
WebhookNotify bool `json:"webhookNotify" yaml:"webhookNotify"`
// Auto-Approval
AutoApproveAfter time.Duration `json:"autoApproveAfter" yaml:"autoApproveAfter"`
TrustFrequentDest bool `json:"trustFrequentDest" yaml:"trustFrequentDest"` // Trust frequent destinations
}
TravelConfig configures travel notifications
type TrustedLocation ΒΆ
type TrustedLocation struct {
bun.BaseModel `bun:"table:trusted_locations,alias:tl"`
ID xid.ID `bun:"id,pk,type:varchar(20)" json:"id"`
UserID xid.ID `bun:"user_id,type:varchar(20),notnull" json:"userId"`
AppID xid.ID `bun:"app_id,type:varchar(20),notnull" json:"appId"`
// Location
Name string `bun:"name,notnull" json:"name"` // e.g., "Home", "Office"
Description string `bun:"description" json:"description"`
Country string `bun:"country,notnull" json:"country"`
CountryCode string `bun:"country_code,notnull" json:"countryCode"`
Region string `bun:"region" json:"region"`
City string `bun:"city" json:"city"`
Latitude float64 `bun:"latitude" json:"latitude"`
Longitude float64 `bun:"longitude" json:"longitude"`
RadiusKm float64 `bun:"radius_km,notnull" json:"radiusKm"` // Trust radius
// Trust Settings
AutoApprove bool `bun:"auto_approve" json:"autoApprove"`
SkipMFA bool `bun:"skip_mfa" json:"skipMfa"`
// Usage Statistics
UsageCount int `bun:"usage_count" json:"usageCount"`
FirstUsedAt time.Time `bun:"first_used_at" json:"firstUsedAt"`
LastUsedAt *time.Time `bun:"last_used_at" json:"lastUsedAt,omitempty"`
// Metadata
CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp" json:"createdAt"`
UpdatedAt time.Time `bun:"updated_at,notnull,default:current_timestamp" json:"updatedAt"`
ExpiresAt *time.Time `bun:"expires_at" json:"expiresAt,omitempty"`
}
TrustedLocation represents a user's trusted location
type VPNAPIProvider ΒΆ
type VPNAPIProvider struct {
// contains filtered or unexported fields
}
VPNAPIProvider implements DetectionProvider using vpnapi.io
func NewVPNAPIProvider ΒΆ
func NewVPNAPIProvider(apiKey string) *VPNAPIProvider
NewVPNAPIProvider creates a new vpnapi.io provider
func (*VPNAPIProvider) Check ΒΆ
func (p *VPNAPIProvider) Check(ctx context.Context, ip string) (*DetectionResult, error)
func (*VPNAPIProvider) Name ΒΆ
func (p *VPNAPIProvider) Name() string