Compare commits

...

3 Commits

Author SHA1 Message Date
8ec34cfbeb Ignore vim swapfiles
Some checks failed
Bandit / build (3.11) (push) Successful in 10s
Flake8 / build (3.11) (push) Successful in 9s
Mypy / build (3.11) (push) Failing after 4m30s
Pylint / build (3.11) (push) Successful in 28s
pip-audit / build (3.11) (pull_request) Failing after 12s
2026-03-13 22:26:15 +01:00
479f990044 add more linters 2026-03-13 22:25:24 +01:00
078514b69e Add CORS handling, and load settings from .env
Some checks failed
Flake8 / build (3.11) (push) Successful in 10s
Mypy / build (3.11) (push) Failing after 1m46s
Pylint / build (3.11) (push) Successful in 28s
2026-03-11 19:21:44 +01:00
4 changed files with 67 additions and 4 deletions

View File

@ -0,0 +1,17 @@
---
name: Bandit
on: [push]
# XXX need to do stuff with uv
jobs:
build:
runs-on: freebsd
strategy:
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@v4
- name: Analyse code with Bandit
run: |
bandit -r .

View File

@ -0,0 +1,23 @@
---
name: pip-audit
on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: '0 0 * * 0' # Weekly on Sunday
# XXX need to do stuff with uv
jobs:
build:
runs-on: freebsd
strategy:
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@v4
- name: Check vulnerable components with pip-audit
run: |
pip-audit .

2
.gitignore vendored
View File

@ -160,3 +160,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
# Vim swap files
*.sw?

View File

@ -1,19 +1,40 @@
'''
Simple Geolocation with FastAPI
'''
import os
from ipaddress import IPv4Address, IPv4Network, IPv6Address, IPv6Network
from typing import Annotated, Optional, Union
import geoip2.database
from geoip2.errors import AddressNotFoundError
from fastapi import FastAPI, Path, Body, Request, Response, status
from dotenv import load_dotenv
from fastapi import Body, FastAPI, Path, Request, Response, status
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import RedirectResponse
from geoip2.errors import AddressNotFoundError
from pydantic import BaseModel
# Load environment variables
load_dotenv()
app = FastAPI()
GEOLITE2_ASN_DB = '/usr/local/share/GeoIP/GeoLite2-ASN.mmdb'
GEOLITE2_CITY_DB = '/usr/local/share/GeoIP/GeoLite2-City.mmdb'
# Configure CORS from environment variables
cors_origins = os.getenv('CORS_ALLOW_ORIGINS', 'http://localhost')
allow_origins = [origin.strip() for origin in cors_origins.split(',')
if origin.strip()]
app.add_middleware(
CORSMiddleware,
allow_origins=allow_origins,
allow_credentials=True,
allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"],
allow_headers=["*"],
)
GEOLITE2_ASN_DB = os.getenv('GEOLITE2_ASN_DB',
'/usr/local/share/GeoIP/GeoLite2-ASN.mmdb')
GEOLITE2_CITY_DB = os.getenv('GEOLITE2_CITY_DB',
'/usr/local/share/GeoIP/GeoLite2-City.mmdb')
class IPAddressParam(BaseModel):