Skip to content

Commit

Permalink
Merge pull request #14 from leirn/mongodb_backend
Browse files Browse the repository at this point in the history
Mongodb backend
  • Loading branch information
leirn committed Jan 22, 2024
2 parents af0a3c6 + 25d0749 commit 0e5dfea
Show file tree
Hide file tree
Showing 16 changed files with 2,316 additions and 323 deletions.
888 changes: 824 additions & 64 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nav_data"
version = "0.1.0"
version = "0.1.5"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -10,7 +10,7 @@ zstd = "0.13.0"
actix = "0.13.1"
actix-cors = "0.7"
actix-web = "4.4.1"
env_logger = "0.10.0"
env_logger = "0.11.0"
log = "0.4"
reqwest = { version = "0.11", default-features = false, features = ["blocking", "json", "rustls-tls"] }
serde = {version = "1.0.163", features = ["derive"] }
Expand All @@ -20,4 +20,17 @@ sqlite = "0.32.0"
actix-rt = "2.9.0"
tokio = "1.35.1"
derive_more = "0.99.17"
async-trait = "0.1.77"
mongodb = "2.8.0"
bson = "2.8.1"
clap = { version = "4.4.18", features = ["derive"] }
clap_derive = "4.4.7"
futures = "0.3.30"
serde_yaml = "0.9.30"

[dependencies.uuid]
version = "1.7.0"
features = [
"v4", # Lets you generate random UUIDs
"fast-rng", # Use a faster (but still sufficiently random) RNG
"macro-diagnostics", # Enable better diagnostics for compile-time UUIDs
]
17 changes: 4 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LABEL maintainer="Laurent <laurent@vromman.org>" \
org.opencontainers.image.vendor="Laurent Vromman" \
org.opencontainers.image.documentation="https://github.com/leirn/navdata/README.md" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.version="0.1.3" \
org.opencontainers.image.version="0.1.5" \
org.opencontainers.image.url="https://github.com/leirn/navdata/" \
org.opencontainers.image.source="https://github.com/leirn/navdata/" \
org.opencontainers.image.revision=$VCS_REF \
Expand All @@ -20,21 +20,12 @@ COPY . /app
RUN apt-get update && apt-get -y install sqlite3
RUN cargo build --release

FROM gcr.io/distroless/cc-debian12
FROM gcr.io/distroless/cc-debian12:lastest

ENV DATABASE_FOLDER=/data

VOLUME "/data"

ENV HOST=0.0.0.0

ENV PORT=8080

ARG DATABASE_PATH=":memory:"
ENV DATABASE_PATH=${DATABASE_PATH}

ARG TOKEN_LIST=""
ENV TOKEN_LIST=${TOKEN_LIST}
VOLUME "/config"

ARG RUST_LOG="warn"
ENV RUST_LOG=${RUST_LOG}
Expand All @@ -46,4 +37,4 @@ EXPOSE 8080

COPY --from=build-env /app/target/release/nav_data /
COPY --from=build-env /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6 /usr/lib/x86_64-linux-gnu/libsqlite3.so.0
CMD ["./nav_data"]
CMD ["./nav_data --config /config/config.yaml"]
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,24 @@ This data MUST NOT be used to plan real life flights.
- ```GET /airport?search={query}``` : look for an airport based on ```query``` string. Answer first 100 results
- ```GET /airport/{icao}``` : look for an airport based on its ICAO code
- ```GET /navaid?search={query}``` : look for a navaid (VOR, DME, ADF...) based on ```query``` string. Answer first 100 results
- ```GET /navaid/{icao}``` : look for an navaid based on its ICAO code
- ```GET /navaid/{icao}``` : look for an navaid based on its ICAO code

### Config file

Config files must be given for docker as ```/config/config.yaml```.

Format is:

```yaml
http:
host: 127.0.0.1
port: 8080
security:
auth_tokens:
- aaaa
- bbbb
- cccc
database:
backend : MONGODB # can be either SQLITE or MONGODB
path : mongodb://localhost:27017 # Mongo URI if mongo (mandatory. Path to sqlite file if sqlite. If sqlite and no path, memory is used
```
3 changes: 2 additions & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ PORT = "8080"
RUST_BACKTRACE="0"
RUST_LOG="info"
HTTPS="false"
TOKEN_LIST="aaaa,bbbb,cccc"
TOKEN_LIST="aaaa,bbbb,cccc"
MONGODB_URL="mongodb://localhost:27017"
11 changes: 11 additions & 0 deletions navdata_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
http:
host: 127.0.0.1
port: 8080
security:
auth_tokens:
- aaaa
- bbbb
- cccc
database:
backend : MONGODB # can be either SQLITE or MONGODB
path : mongodb://localhost:27017 # Mongo URI if mongo (mandatory. Path to sqlite file if sqlite. If sqlite and no path, memory is used
27 changes: 27 additions & 0 deletions src/app/config/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use serde::Deserialize;

use super::db::BackendType;

#[derive(Debug, Deserialize, Default)]
pub struct Config {
pub http: HttpConfig,
pub security: SecurityConfig,
pub database: DatabaseConfig,
}

#[derive(Debug, Deserialize, Default)]
pub struct HttpConfig {
pub host: String,
pub port: u16,
}

#[derive(Debug, Deserialize, Default)]
pub struct SecurityConfig {
pub auth_tokens: Vec<String>,
}

#[derive(Debug, Deserialize, Default)]
pub struct DatabaseConfig {
pub backend: BackendType,
pub path: Option<String>,
}
Loading

0 comments on commit 0e5dfea

Please sign in to comment.