Skip to content

Commit 51b45c7

Browse files
authored
Merge pull request #138 from pbogre/ext-api-opt-out
Add `ENABLE_EXTERNAL_APIS` env variable to opt out of using external apis
2 parents 42739e2 + 420612a commit 51b45c7

8 files changed

Lines changed: 40 additions & 12 deletions

File tree

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ ENV APP_PATH=/app
3131
ENV DATA_PATH=/data
3232
ENV JETLOG_PORT=3000
3333
ENV TOKEN_DURATION=7
34+
ENV ENABLE_EXTERNAL_APIS=true
3435
ENV USE_IPV6=false
3536

3637
RUN mkdir -p ${APP_PATH}

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ A self-hostable personal flight tracker and viewer
1515
- [Features](#features)
1616
- [Getting Started](#getting-started)
1717
- [Importing & Exporting](#importing--exporting)
18+
- [Privacy Notice](#privacy-notice)
1819
- [Contributing](#contributing)
1920
- [Stack](#stack)
2021
- [Acknowledgements](#acknowledgements)
@@ -61,6 +62,14 @@ you can also export to CSV, iCal
6162

6263
For details on how to import your data, have a look at the [importing wiki](https://github.com/pbogre/jetlog/wiki/Importing)
6364

65+
## Privacy Notice
66+
67+
Jetlog itself does not collect any user data outside of your own setup. However,
68+
it relies on external APIs ([adsbdb](https://www.adsbdb.com/)) for some features
69+
such as automatic flight fetching from the flight number. Since you cannot always
70+
be sure of how external APIs use your data, you may wish to opt out of these by setting
71+
the `ENABLE_EXTERNAL_APIS` environment variable to `false`.
72+
6473
## Contributing
6574

6675
If you would like to contribute to this project by opening an issue or a pull request,

client/api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import axios, {Axios} from 'axios';
22
import TokenStorage from './storage/tokenStorage';
33

44
const config = await fetch('./config').then((response) => response.json())
5-
.catch(() => ({ BASE_URL: '/' }));
5+
.catch(() => ({ BASE_URL: '/', ENABLE_EXTERNAL_APIS: true }));
66

77
export const BASE_URL = config.BASE_URL == '/' ? '' : config.BASE_URL;
8+
export const ENABLE_EXTERNAL_APIS = config.ENABLE_EXTERNAL_APIS;
89

910
// TODO improve this because there's a lot of repetition (get, post, delete are pretty much exactly the same)
1011
// perhaps one method for each endpoint? i.e. API.getFlights(), ...

client/pages/New.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useNavigate } from 'react-router-dom';
33

44
import { Heading, Label, Button, Input, Select, TextArea } from '../components/Elements';
55
import SearchInput from '../components/SearchInput'
6-
import API from '../api';
6+
import API, { ENABLE_EXTERNAL_APIS } from '../api';
77
import { objectFromForm } from '../utils';
88
import { Airline, Airport, User } from '../models';
99
import ConfigStorage from '../storage/configStorage';
@@ -151,6 +151,10 @@ export default function New() {
151151
};
152152

153153
const attemptFetchFlight = async () => {
154+
if (!ENABLE_EXTERNAL_APIS) {
155+
return;
156+
}
157+
154158
API.getRemote(`https://api.adsbdb.com/v0/callsign/${flightNumber}`)
155159
.then(async (data: Object) => {
156160
const originICAO = data["response"]["flightroute"]["origin"]["icao_code"];
@@ -246,9 +250,11 @@ export default function New() {
246250
onChange={(e) => setFlightNumber(e.target.value)}
247251
/>
248252
</div>
249-
<div className="h-10 flex items-center">
250-
<Button text="Fetch" onClick={attemptFetchFlight} disabled={!flightNumber} />
251-
</div>
253+
{ ENABLE_EXTERNAL_APIS &&
254+
<div className="h-10 flex items-center">
255+
<Button text="Fetch" onClick={attemptFetchFlight} disabled={!flightNumber} />
256+
</div>
257+
}
252258
</div>
253259
<div>
254260
<Label text="Connection" />

client/pages/Settings.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState, useEffect } from 'react';
22
import { useNavigate } from 'react-router-dom';
33

4-
import API from '../api';
4+
import API, { ENABLE_EXTERNAL_APIS } from '../api';
55
import { Heading, Label, Input, Checkbox, Subheading, Button, Dialog, Select } from '../components/Elements'
66
import ConfigStorage, { ConfigInterface } from '../storage/configStorage';
77
import { User } from '../models';
@@ -255,10 +255,12 @@ export default function Settings() {
255255
<Button text="Run" disabled={disableJobs} onClick={computeConnections} />
256256
</div>
257257

258-
<div className="flex justify-between">
259-
<Label text="Fetch missing airlines" />
260-
<Button text="Run" disabled={disableJobs} onClick={fetchAirlinesFromCallsigns} />
261-
</div>
258+
{ ENABLE_EXTERNAL_APIS &&
259+
<div className="flex justify-between">
260+
<Label text="Fetch missing airlines" />
261+
<Button text="Run" disabled={disableJobs} onClick={fetchAirlinesFromCallsigns} />
262+
</div>
263+
}
262264
</div>
263265

264266

server/environment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import sys
33

4-
def _get_environment_variable(key: str, cast_int: bool = False, required: bool = True) -> str|int|None:
4+
def _get_environment_variable(key: str, cast_int: bool = False, cast_str: bool = False, required: bool = True) -> str|int|None:
55
value = os.environ.get(key)
66

77
if not value:
@@ -23,3 +23,4 @@ def _get_environment_variable(key: str, cast_int: bool = False, required: bool =
2323
SECRET_KEY = _get_environment_variable("SECRET_KEY")
2424
AUTH_HEADER = _get_environment_variable("AUTH_HEADER", required=False)
2525
TOKEN_DURATION = _get_environment_variable("TOKEN_DURATION", cast_int=True)
26+
ENABLE_EXTERNAL_APIS = str(_get_environment_variable("ENABLE_EXTERNAL_APIS")).lower() == "true"

server/main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from server.routers import flights, airports, airlines, statistics, geography, importing, exporting
22
from server.auth import users, auth
3+
from server.environment import ENABLE_EXTERNAL_APIS
34
from fastapi import FastAPI, Depends, Request
45
from fastapi.responses import HTMLResponse, JSONResponse
56
from fastapi.staticfiles import StaticFiles
@@ -34,7 +35,11 @@
3435

3536
@app.get("/config")
3637
async def get_config(request: Request):
37-
return JSONResponse({"BASE_URL": request.scope.get("root_path", "/")})
38+
config = {
39+
"BASE_URL": request.scope.get("root_path", "/"),
40+
"ENABLE_EXTERNAL_APIS": ENABLE_EXTERNAL_APIS
41+
}
42+
return JSONResponse(config)
3843

3944
@app.get("/", include_in_schema=False)
4045
@app.get("/new", include_in_schema=False)

server/routers/flights.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from server.database import database
2+
from server.environment import ENABLE_EXTERNAL_APIS
23
from server.models import AirlineModel, AirportModel, ClassType, CustomModel, FlightModel, AircraftSide, FlightPurpose, SeatType, User
34
from server.auth.users import get_current_user
45

@@ -363,6 +364,8 @@ async def compute_connections(user: User = Depends(get_current_user)) -> dict:
363364

364365
@router.post("/airlines_from_callsigns", status_code=200)
365366
async def fetch_airlines_from_callsigns(user: User = Depends(get_current_user)) -> dict:
367+
if not ENABLE_EXTERNAL_APIS:
368+
raise HTTPException(status_code=400, detail="This endpoint relies on the use of an external API, which you have opted out of.")
366369
import requests
367370

368371
res = database.execute_read_query("""SELECT flight_number, COUNT(*)

0 commit comments

Comments
 (0)