Skip to content

Commit 0e5dfea

Browse files
authored
Merge pull request #14 from leirn/mongodb_backend
Mongodb backend
2 parents af0a3c6 + 25d0749 commit 0e5dfea

16 files changed

+2316
-323
lines changed

Cargo.lock

+824-64
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "nav_data"
3-
version = "0.1.0"
3+
version = "0.1.5"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -10,7 +10,7 @@ zstd = "0.13.0"
1010
actix = "0.13.1"
1111
actix-cors = "0.7"
1212
actix-web = "4.4.1"
13-
env_logger = "0.10.0"
13+
env_logger = "0.11.0"
1414
log = "0.4"
1515
reqwest = { version = "0.11", default-features = false, features = ["blocking", "json", "rustls-tls"] }
1616
serde = {version = "1.0.163", features = ["derive"] }
@@ -20,4 +20,17 @@ sqlite = "0.32.0"
2020
actix-rt = "2.9.0"
2121
tokio = "1.35.1"
2222
derive_more = "0.99.17"
23-
async-trait = "0.1.77"
23+
mongodb = "2.8.0"
24+
bson = "2.8.1"
25+
clap = { version = "4.4.18", features = ["derive"] }
26+
clap_derive = "4.4.7"
27+
futures = "0.3.30"
28+
serde_yaml = "0.9.30"
29+
30+
[dependencies.uuid]
31+
version = "1.7.0"
32+
features = [
33+
"v4", # Lets you generate random UUIDs
34+
"fast-rng", # Use a faster (but still sufficiently random) RNG
35+
"macro-diagnostics", # Enable better diagnostics for compile-time UUIDs
36+
]

Dockerfile

+4-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LABEL maintainer="Laurent <laurent@vromman.org>" \
99
org.opencontainers.image.vendor="Laurent Vromman" \
1010
org.opencontainers.image.documentation="https://github.com/leirn/navdata/README.md" \
1111
org.opencontainers.image.licenses="MIT" \
12-
org.opencontainers.image.version="0.1.3" \
12+
org.opencontainers.image.version="0.1.5" \
1313
org.opencontainers.image.url="https://github.com/leirn/navdata/" \
1414
org.opencontainers.image.source="https://github.com/leirn/navdata/" \
1515
org.opencontainers.image.revision=$VCS_REF \
@@ -20,21 +20,12 @@ COPY . /app
2020
RUN apt-get update && apt-get -y install sqlite3
2121
RUN cargo build --release
2222

23-
FROM gcr.io/distroless/cc-debian12
23+
FROM gcr.io/distroless/cc-debian12:lastest
2424

2525
ENV DATABASE_FOLDER=/data
2626

2727
VOLUME "/data"
28-
29-
ENV HOST=0.0.0.0
30-
31-
ENV PORT=8080
32-
33-
ARG DATABASE_PATH=":memory:"
34-
ENV DATABASE_PATH=${DATABASE_PATH}
35-
36-
ARG TOKEN_LIST=""
37-
ENV TOKEN_LIST=${TOKEN_LIST}
28+
VOLUME "/config"
3829

3930
ARG RUST_LOG="warn"
4031
ENV RUST_LOG=${RUST_LOG}
@@ -46,4 +37,4 @@ EXPOSE 8080
4637

4738
COPY --from=build-env /app/target/release/nav_data /
4839
COPY --from=build-env /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6 /usr/lib/x86_64-linux-gnu/libsqlite3.so.0
49-
CMD ["./nav_data"]
40+
CMD ["./nav_data --config /config/config.yaml"]

README.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,24 @@ This data MUST NOT be used to plan real life flights.
2828
- ```GET /airport?search={query}``` : look for an airport based on ```query``` string. Answer first 100 results
2929
- ```GET /airport/{icao}``` : look for an airport based on its ICAO code
3030
- ```GET /navaid?search={query}``` : look for a navaid (VOR, DME, ADF...) based on ```query``` string. Answer first 100 results
31-
- ```GET /navaid/{icao}``` : look for an navaid based on its ICAO code
31+
- ```GET /navaid/{icao}``` : look for an navaid based on its ICAO code
32+
33+
### Config file
34+
35+
Config files must be given for docker as ```/config/config.yaml```.
36+
37+
Format is:
38+
39+
```yaml
40+
http:
41+
host: 127.0.0.1
42+
port: 8080
43+
security:
44+
auth_tokens:
45+
- aaaa
46+
- bbbb
47+
- cccc
48+
database:
49+
backend : MONGODB # can be either SQLITE or MONGODB
50+
path : mongodb://localhost:27017 # Mongo URI if mongo (mandatory. Path to sqlite file if sqlite. If sqlite and no path, memory is used
51+
```

config.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ PORT = "8080"
44
RUST_BACKTRACE="0"
55
RUST_LOG="info"
66
HTTPS="false"
7-
TOKEN_LIST="aaaa,bbbb,cccc"
7+
TOKEN_LIST="aaaa,bbbb,cccc"
8+
MONGODB_URL="mongodb://localhost:27017"

navdata_config.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
http:
2+
host: 127.0.0.1
3+
port: 8080
4+
security:
5+
auth_tokens:
6+
- aaaa
7+
- bbbb
8+
- cccc
9+
database:
10+
backend : MONGODB # can be either SQLITE or MONGODB
11+
path : mongodb://localhost:27017 # Mongo URI if mongo (mandatory. Path to sqlite file if sqlite. If sqlite and no path, memory is used

src/app/config/mod.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use serde::Deserialize;
2+
3+
use super::db::BackendType;
4+
5+
#[derive(Debug, Deserialize, Default)]
6+
pub struct Config {
7+
pub http: HttpConfig,
8+
pub security: SecurityConfig,
9+
pub database: DatabaseConfig,
10+
}
11+
12+
#[derive(Debug, Deserialize, Default)]
13+
pub struct HttpConfig {
14+
pub host: String,
15+
pub port: u16,
16+
}
17+
18+
#[derive(Debug, Deserialize, Default)]
19+
pub struct SecurityConfig {
20+
pub auth_tokens: Vec<String>,
21+
}
22+
23+
#[derive(Debug, Deserialize, Default)]
24+
pub struct DatabaseConfig {
25+
pub backend: BackendType,
26+
pub path: Option<String>,
27+
}

0 commit comments

Comments
 (0)