Compare commits
22 Commits
workflows
...
feature/ng
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a0111c4c5 | ||
|
|
0575c34fd6 | ||
|
|
1daac01583 | ||
| cd28b5009a | |||
|
|
171e505f22 | ||
|
|
dff828addf | ||
|
|
1481e31182 | ||
|
|
4b80619c97 | ||
|
|
836617fa54 | ||
|
|
e74ddb96ab | ||
|
|
86e9fd42bb | ||
|
|
d9fe053d41 | ||
|
|
1eeca606ec | ||
|
|
6ce8850ddb | ||
|
|
a9a08d2ef8 | ||
|
|
bbde3c1b60 | ||
|
|
e2d364722b | ||
|
|
da0ab29b2a | ||
|
|
60af2c5b80 | ||
| a1996adc45 | |||
|
|
e831640540 | ||
|
|
a023cbc082 |
59
.github/workflows/test.yaml
vendored
59
.github/workflows/test.yaml
vendored
@@ -45,13 +45,35 @@ jobs:
|
|||||||
- name: Restore frontend build cache
|
- name: Restore frontend build cache
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: apps/nxmesh-frontend/build
|
path: apps/nxmesh-frontend/dist
|
||||||
key: frontend-build-${{ runner.os }}-run-${{ github.run_id }}
|
key: frontend-build-${{ runner.os }}-run-${{ github.run_id }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
frontend-build-${{ runner.os }}-
|
frontend-build-${{ runner.os }}-
|
||||||
|
|
||||||
|
# TODO: uncomment until artifact hanlding fixed in gitea
|
||||||
|
# - name: Download frontend build artifact
|
||||||
|
# uses: actions/download-artifact@v4
|
||||||
|
# with:
|
||||||
|
# name: frontend-dist
|
||||||
|
# path: apps/nxmesh-frontend/dist
|
||||||
|
|
||||||
|
# - name: Copy frontend build to expected location
|
||||||
|
# run: |
|
||||||
|
# # unlink frontend-dist
|
||||||
|
# rm -f apps/nxmesh-master/frontend-dist || true
|
||||||
|
# rm -rf apps/nxmesh-master/frontend-dist || true
|
||||||
|
# cp -r apps/nxmesh-frontend/dist apps/nxmesh-master/frontend-dist
|
||||||
|
|
||||||
|
# ls -la apps/nxmesh-master/frontend-dist
|
||||||
|
|
||||||
|
- name: Create dummy build artifacts
|
||||||
|
run: |
|
||||||
|
rm -f apps/nxmesh-master/frontend-dist || true
|
||||||
|
mkdir -p apps/nxmesh-master/frontend-dist
|
||||||
|
echo "<html><body><h1>Dummy Build</h1></body></html>" > apps/nxmesh-master/frontend-dist/index.html
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: cargo test --all-features
|
run: cargo test --all-features -- --show-output
|
||||||
|
|
||||||
lint-crates:
|
lint-crates:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -74,11 +96,31 @@ jobs:
|
|||||||
- name: Restore frontend build cache
|
- name: Restore frontend build cache
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: apps/nxmesh-frontend/build
|
path: apps/nxmesh-frontend/dist
|
||||||
key: frontend-build-${{ runner.os }}-run-${{ github.run_id }}
|
key: frontend-build-${{ runner.os }}-run-${{ github.run_id }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
frontend-build-${{ runner.os }}-
|
frontend-build-${{ runner.os }}-
|
||||||
|
|
||||||
|
# TODO: uncomment until artifact hanlding fixed in gitea
|
||||||
|
# - name: Download frontend build artifact
|
||||||
|
# uses: actions/download-artifact@v4
|
||||||
|
# with:
|
||||||
|
# name: frontend-dist
|
||||||
|
# path: apps/nxmesh-frontend/dist
|
||||||
|
|
||||||
|
# - name: Copy frontend build to expected location
|
||||||
|
# run: |
|
||||||
|
# # unlink frontend-dist
|
||||||
|
# rm -f apps/nxmesh-master/frontend-dist || true
|
||||||
|
# rm -rf apps/nxmesh-master/frontend-dist || true
|
||||||
|
# cp -r apps/nxmesh-frontend/dist apps/nxmesh-master/frontend-dist
|
||||||
|
|
||||||
|
- name: Create dummy build artifacts
|
||||||
|
run: |
|
||||||
|
rm -f apps/nxmesh-master/frontend-dist || true
|
||||||
|
mkdir -p apps/nxmesh-master/frontend-dist
|
||||||
|
echo "<html><body><h1>Dummy Build</h1></body></html>" > apps/nxmesh-master/frontend-dist/index.html
|
||||||
|
|
||||||
- name: Run clippy
|
- name: Run clippy
|
||||||
run: cargo clippy --all-features
|
run: cargo clippy --all-features
|
||||||
|
|
||||||
@@ -147,7 +189,12 @@ jobs:
|
|||||||
- name: Cache frontend build
|
- name: Cache frontend build
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: apps/nxmesh-frontend/build
|
path: apps/nxmesh-frontend/dist
|
||||||
key: frontend-build-${{ runner.os }}-run-${{ github.run_id }}
|
key: frontend-build-${{ runner.os }}-run-${{ github.run_id }}
|
||||||
restore-keys: |
|
# IGNORE restore-keys
|
||||||
frontend-build-${{ runner.os }}-
|
# TODO: uncomment until artifact hanlding fixed in gitea
|
||||||
|
# - name: Upload frontend build artifact
|
||||||
|
# uses: actions/upload-artifact@v4
|
||||||
|
# with:
|
||||||
|
# name: frontend-dist
|
||||||
|
# path: apps/nxmesh-frontend/dist
|
||||||
|
|||||||
6
.github/workflows/verify.yaml
vendored
6
.github/workflows/verify.yaml
vendored
@@ -109,14 +109,14 @@ jobs:
|
|||||||
- name: Apply migrations
|
- name: Apply migrations
|
||||||
if: steps.check_changes.outputs.changed == 'true'
|
if: steps.check_changes.outputs.changed == 'true'
|
||||||
run: |
|
run: |
|
||||||
cargo run -p nxmesh-migration -- up
|
cd crates && sea-orm-cli migrate up
|
||||||
|
|
||||||
- name: Regenerate entities
|
- name: Regenerate entities
|
||||||
if: steps.check_changes.outputs.changed == 'true'
|
if: steps.check_changes.outputs.changed == 'true'
|
||||||
run: |
|
run: |
|
||||||
sea-orm-cli generate entity \
|
cd crates && sea-orm-cli generate entity \
|
||||||
--database-url "$DATABASE_URL" \
|
--database-url "$DATABASE_URL" \
|
||||||
--output-dir apps/nxmesh-master/src/db/entities \
|
--output-dir ../apps/nxmesh-master/src/db/entities \
|
||||||
--with-serde both \
|
--with-serde both \
|
||||||
--with-copy-enums \
|
--with-copy-enums \
|
||||||
--date-time-crate chrono
|
--date-time-crate chrono
|
||||||
|
|||||||
279
Cargo.lock
generated
279
Cargo.lock
generated
@@ -538,6 +538,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "8b52af3cb4058c895d37317bb27508dccc8e5f2d39454016b297bf4a400597b8"
|
checksum = "8b52af3cb4058c895d37317bb27508dccc8e5f2d39454016b297bf4a400597b8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum-core",
|
"axum-core",
|
||||||
|
"axum-macros",
|
||||||
"base64",
|
"base64",
|
||||||
"bytes",
|
"bytes",
|
||||||
"form_urlencoded",
|
"form_urlencoded",
|
||||||
@@ -586,6 +587,45 @@ dependencies = [
|
|||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "axum-macros"
|
||||||
|
version = "0.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7aa268c23bfbbd2c4363b9cd302a4f504fb2a9dfe7e3451d66f35dd392e20aca"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.117",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "axum-test"
|
||||||
|
version = "20.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3a86bfe2ef15bee102ac34912f7f4542b0bb37dc464fa55461763999c4d625e7"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"axum",
|
||||||
|
"bytes",
|
||||||
|
"bytesize",
|
||||||
|
"cookie",
|
||||||
|
"expect-json",
|
||||||
|
"http",
|
||||||
|
"http-body-util",
|
||||||
|
"hyper",
|
||||||
|
"hyper-util",
|
||||||
|
"mime",
|
||||||
|
"pretty_assertions",
|
||||||
|
"reserve-port",
|
||||||
|
"rust-multipart-rfc7578_2",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"serde_urlencoded",
|
||||||
|
"tokio",
|
||||||
|
"tower",
|
||||||
|
"url",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "base64"
|
name = "base64"
|
||||||
version = "0.22.1"
|
version = "0.22.1"
|
||||||
@@ -727,6 +767,12 @@ version = "1.11.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
|
checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bytesize"
|
||||||
|
version = "2.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6bd91ee7b2422bcb158d90ef4d14f75ef67f340943fc4149891dcce8f8b972a3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bzip2"
|
name = "bzip2"
|
||||||
version = "0.6.1"
|
version = "0.6.1"
|
||||||
@@ -911,6 +957,16 @@ dependencies = [
|
|||||||
"unicode-segmentation",
|
"unicode-segmentation",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cookie"
|
||||||
|
version = "0.18.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4ddef33a339a91ea89fb53151bd0a4689cfce27055c291dfa69945475d22c747"
|
||||||
|
dependencies = [
|
||||||
|
"time",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation"
|
name = "core-foundation"
|
||||||
version = "0.10.1"
|
version = "0.10.1"
|
||||||
@@ -1135,6 +1191,12 @@ dependencies = [
|
|||||||
"unicode-xid",
|
"unicode-xid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "diff"
|
||||||
|
version = "0.1.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "digest"
|
name = "digest"
|
||||||
version = "0.10.7"
|
version = "0.10.7"
|
||||||
@@ -1188,6 +1250,15 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "email_address"
|
||||||
|
version = "0.2.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e079f19b08ca6239f47f8ba8509c11cf3ea30095831f7fed61441475edd8c449"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "encoding_rs"
|
name = "encoding_rs"
|
||||||
version = "0.8.35"
|
version = "0.8.35"
|
||||||
@@ -1262,6 +1333,35 @@ dependencies = [
|
|||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "expect-json"
|
||||||
|
version = "1.10.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "869f97f4abe8e78fc812a94ad6b721d72c4fb5532877c79610f2c238d7ccf6c4"
|
||||||
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
|
"email_address",
|
||||||
|
"expect-json-macros",
|
||||||
|
"num",
|
||||||
|
"regex",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"thiserror",
|
||||||
|
"typetag",
|
||||||
|
"uuid",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "expect-json-macros"
|
||||||
|
version = "1.10.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6e6fdf550180a6c29a28cb9aac262dc0064c25735641d2317f670075e9a469d9"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.117",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fastrand"
|
name = "fastrand"
|
||||||
version = "2.3.0"
|
version = "2.3.0"
|
||||||
@@ -1343,6 +1443,17 @@ version = "2.0.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "28dd6caf6059519a65843af8fe2a3ae298b14b80179855aeb4adc2c1934ee619"
|
checksum = "28dd6caf6059519a65843af8fe2a3ae298b14b80179855aeb4adc2c1934ee619"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fs4"
|
||||||
|
version = "0.13.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8640e34b88f7652208ce9e88b1a37a2ae95227d84abec377ccd3c5cfeb141ed4"
|
||||||
|
dependencies = [
|
||||||
|
"rustix",
|
||||||
|
"tokio",
|
||||||
|
"windows-sys 0.59.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "funty"
|
name = "funty"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
@@ -1964,6 +2075,15 @@ dependencies = [
|
|||||||
"generic-array",
|
"generic-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "inventory"
|
||||||
|
version = "0.3.24"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a4f0c30c76f2f4ccee3fe55a2435f691ca00c0e4bd87abe4f4a851b1d4dac39b"
|
||||||
|
dependencies = [
|
||||||
|
"rustversion",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "is_terminal_polyfill"
|
name = "is_terminal_polyfill"
|
||||||
version = "1.70.2"
|
version = "1.70.2"
|
||||||
@@ -2334,6 +2454,20 @@ dependencies = [
|
|||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23"
|
||||||
|
dependencies = [
|
||||||
|
"num-bigint",
|
||||||
|
"num-complex",
|
||||||
|
"num-integer",
|
||||||
|
"num-iter",
|
||||||
|
"num-rational",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-bigint"
|
name = "num-bigint"
|
||||||
version = "0.4.6"
|
version = "0.4.6"
|
||||||
@@ -2410,6 +2544,17 @@ dependencies = [
|
|||||||
"num-modular",
|
"num-modular",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-rational"
|
||||||
|
version = "0.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824"
|
||||||
|
dependencies = [
|
||||||
|
"num-bigint",
|
||||||
|
"num-integer",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-traits"
|
name = "num-traits"
|
||||||
version = "0.2.19"
|
version = "0.2.19"
|
||||||
@@ -2424,10 +2569,12 @@ dependencies = [
|
|||||||
name = "nxmesh-agent"
|
name = "nxmesh-agent"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
"config",
|
"config",
|
||||||
|
"fs4",
|
||||||
"futures",
|
"futures",
|
||||||
"hex",
|
"hex",
|
||||||
"hostname",
|
"hostname",
|
||||||
@@ -2470,6 +2617,7 @@ dependencies = [
|
|||||||
"async-stream",
|
"async-stream",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"axum",
|
"axum",
|
||||||
|
"axum-test",
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap",
|
"clap",
|
||||||
"config",
|
"config",
|
||||||
@@ -2477,12 +2625,14 @@ dependencies = [
|
|||||||
"handlebars",
|
"handlebars",
|
||||||
"hex",
|
"hex",
|
||||||
"jsonwebtoken",
|
"jsonwebtoken",
|
||||||
|
"mime_guess",
|
||||||
"mockall",
|
"mockall",
|
||||||
"nxmesh-core",
|
"nxmesh-core",
|
||||||
"nxmesh-migration",
|
"nxmesh-migration",
|
||||||
"nxmesh-proto",
|
"nxmesh-proto",
|
||||||
"rand 0.10.0",
|
"rand 0.10.0",
|
||||||
"rcgen",
|
"rcgen",
|
||||||
|
"rust-embed",
|
||||||
"sea-orm",
|
"sea-orm",
|
||||||
"sea-orm-migration",
|
"sea-orm-migration",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -2932,6 +3082,16 @@ dependencies = [
|
|||||||
"termtree",
|
"termtree",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pretty_assertions"
|
||||||
|
version = "1.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3ae130e2f271fbc2ac3a40fb1d07180839cdbbe443c7a27e1e3c13c5cac0116d"
|
||||||
|
dependencies = [
|
||||||
|
"diff",
|
||||||
|
"yansi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "prettyplease"
|
name = "prettyplease"
|
||||||
version = "0.2.37"
|
version = "0.2.37"
|
||||||
@@ -3261,6 +3421,15 @@ dependencies = [
|
|||||||
"bytecheck",
|
"bytecheck",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "reserve-port"
|
||||||
|
version = "2.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "94070964579245eb2f76e62a7668fe87bd9969ed6c41256f3bf614e3323dd3cc"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ring"
|
name = "ring"
|
||||||
version = "0.17.14"
|
version = "0.17.14"
|
||||||
@@ -3338,6 +3507,40 @@ dependencies = [
|
|||||||
"zeroize",
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rust-embed"
|
||||||
|
version = "8.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "04113cb9355a377d83f06ef1f0a45b8ab8cd7d8b1288160717d66df5c7988d27"
|
||||||
|
dependencies = [
|
||||||
|
"rust-embed-impl",
|
||||||
|
"rust-embed-utils",
|
||||||
|
"walkdir",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rust-embed-impl"
|
||||||
|
version = "8.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "da0902e4c7c8e997159ab384e6d0fc91c221375f6894346ae107f47dd0f3ccaa"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"rust-embed-utils",
|
||||||
|
"syn 2.0.117",
|
||||||
|
"walkdir",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rust-embed-utils"
|
||||||
|
version = "8.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5bcdef0be6fe7f6fa333b1073c949729274b05f123a0ad7efcb8efd878e5c3b1"
|
||||||
|
dependencies = [
|
||||||
|
"sha2",
|
||||||
|
"walkdir",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rust-ini"
|
name = "rust-ini"
|
||||||
version = "0.21.3"
|
version = "0.21.3"
|
||||||
@@ -3348,6 +3551,21 @@ dependencies = [
|
|||||||
"ordered-multimap",
|
"ordered-multimap",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rust-multipart-rfc7578_2"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "00bdaa068902270ca7fa8619775e1838e23a63620abac0947ce0f715819b8cec"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"futures-core",
|
||||||
|
"futures-util",
|
||||||
|
"http",
|
||||||
|
"mime",
|
||||||
|
"rand 0.10.0",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rust_decimal"
|
name = "rust_decimal"
|
||||||
version = "1.40.0"
|
version = "1.40.0"
|
||||||
@@ -3454,6 +3672,15 @@ version = "1.0.23"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"
|
checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "same-file"
|
||||||
|
version = "1.0.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-util",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "schannel"
|
name = "schannel"
|
||||||
version = "0.1.28"
|
version = "0.1.28"
|
||||||
@@ -4699,6 +4926,30 @@ version = "1.19.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb"
|
checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "typetag"
|
||||||
|
version = "0.2.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "be2212c8a9b9bcfca32024de14998494cf9a5dfa59ea1b829de98bac374b86bf"
|
||||||
|
dependencies = [
|
||||||
|
"erased-serde",
|
||||||
|
"inventory",
|
||||||
|
"once_cell",
|
||||||
|
"serde",
|
||||||
|
"typetag-impl",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "typetag-impl"
|
||||||
|
version = "0.2.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "27a7a9b72ba121f6f1f6c3632b85604cac41aedb5ddc70accbebb6cac83de846"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.117",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ucd-trie"
|
name = "ucd-trie"
|
||||||
version = "0.1.7"
|
version = "0.1.7"
|
||||||
@@ -4876,6 +5127,16 @@ version = "0.9.5"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "walkdir"
|
||||||
|
version = "2.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
|
||||||
|
dependencies = [
|
||||||
|
"same-file",
|
||||||
|
"winapi-util",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "want"
|
name = "want"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
@@ -5046,6 +5307,15 @@ dependencies = [
|
|||||||
"wasite",
|
"wasite",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-util"
|
||||||
|
version = "0.1.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys 0.61.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-core"
|
name = "windows-core"
|
||||||
version = "0.62.2"
|
version = "0.62.2"
|
||||||
@@ -5123,6 +5393,15 @@ dependencies = [
|
|||||||
"windows-targets 0.52.6",
|
"windows-targets 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.59.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets 0.52.6",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.60.2"
|
version = "0.60.2"
|
||||||
|
|||||||
@@ -56,9 +56,6 @@ futures = "0.3"
|
|||||||
toml = "0.9"
|
toml = "0.9"
|
||||||
config = "0.15"
|
config = "0.15"
|
||||||
|
|
||||||
# HTTP client
|
|
||||||
reqwest = { version = "0.13.2", default-features = false, features = ["json"] }
|
|
||||||
|
|
||||||
# Crypto
|
# Crypto
|
||||||
sha2 = "0.10"
|
sha2 = "0.10"
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ zip = { workspace = true }
|
|||||||
|
|
||||||
# CLI
|
# CLI
|
||||||
clap = { workspace = true, features = ["derive"] }
|
clap = { workspace = true, features = ["derive"] }
|
||||||
|
anyhow = { version = "1.0.102", features = ["backtrace"] }
|
||||||
|
fs4 = { version = "0.13.1", features = ["tokio"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tokio-test.workspace = true
|
tokio-test.workspace = true
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use crate::connector::master::{MasterConnector, MasterConnectorTrait, ssh::SshMa
|
|||||||
mod cli;
|
mod cli;
|
||||||
mod config;
|
mod config;
|
||||||
mod connector;
|
mod connector;
|
||||||
|
mod service;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
@@ -60,13 +61,13 @@ async fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// send a dummy heartbeat to verify the connection is working
|
// send a dummy heartbeat to verify the connection is working
|
||||||
let client = master_connector.get_client();
|
let mut client = master_connector.get_client().lock().await.clone();
|
||||||
|
|
||||||
let request = nxmesh_proto::HealthReport {
|
let request = nxmesh_proto::HealthReport {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
match client.lock().await.report_health(request).await {
|
match client.report_health(request).await {
|
||||||
Ok(_) => info!("Successfully sent health report to master."),
|
Ok(_) => info!("Successfully sent health report to master."),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Failed to send health report to master: {}", e);
|
error!("Failed to send health report to master: {}", e);
|
||||||
|
|||||||
1
apps/nxmesh-agent/src/service/mod.rs
Normal file
1
apps/nxmesh-agent/src/service/mod.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub mod nginx_handler;
|
||||||
495
apps/nxmesh-agent/src/service/nginx_handler.rs
Normal file
495
apps/nxmesh-agent/src/service/nginx_handler.rs
Normal file
@@ -0,0 +1,495 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use fs4::tokio::AsyncFileExt;
|
||||||
|
use tokio::{io::AsyncWriteExt, process::Command};
|
||||||
|
use tracing::{debug, warn};
|
||||||
|
|
||||||
|
use crate::config::settings::NginxSettings;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
use mockall::predicate::*;
|
||||||
|
// TODO: custom error type
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
#[cfg_attr(test, mockall::automock)]
|
||||||
|
pub trait NginxHandler {
|
||||||
|
// Reload nginx to apply new config. The config_path is an optional parameter that specifies the path to the nginx config file to be used for this reload operation. If not provided, the default config path will be used.
|
||||||
|
async fn reload(&self, config_path: Option<&str>) -> Result<()>;
|
||||||
|
async fn stop(&self) -> Result<()>;
|
||||||
|
async fn validate(&self, config_path: Option<&str>) -> Result<()>;
|
||||||
|
async fn get_version(&self) -> Result<String>;
|
||||||
|
async fn get_status(&self) -> Result<String>;
|
||||||
|
// Write a new config file for nginx.
|
||||||
|
// The output_path is a relative path to the nginx config directory of the deployment folder. The actual path to the config should not be assumed by the caller, as it can be different in different environments, but will be promised to be relative to the deployment folder for each the corresponding deployment_id. Path traversal is not allowed.
|
||||||
|
async fn write_config(
|
||||||
|
&self,
|
||||||
|
deployment_id: &str,
|
||||||
|
config_content: &str,
|
||||||
|
output_path: &str,
|
||||||
|
) -> Result<()>;
|
||||||
|
// Append a new config content to an existing config file for nginx. This is useful for some use cases where we want to keep the existing config and just add some new config content to it. The output_path is a relative path to the nginx config directory of the deployment folder, which should be the same as the one used in write_config function. Path traversal is not allowed.
|
||||||
|
async fn append_config(
|
||||||
|
&self,
|
||||||
|
deployment_id: &str,
|
||||||
|
config_content: &str,
|
||||||
|
output_path: &str,
|
||||||
|
) -> Result<()>;
|
||||||
|
|
||||||
|
// clean up old config files that are applied to nginx
|
||||||
|
// keep only latest n deployments.
|
||||||
|
async fn cleanup_config(&self, n: usize) -> Result<()>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct NginxHandlerImpl {
|
||||||
|
settings: Arc<NginxSettings>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl NginxHandlerImpl {
|
||||||
|
pub fn new(settings: Arc<NginxSettings>) -> Self {
|
||||||
|
Self { settings }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_nginx_command(&self) -> String {
|
||||||
|
// TODO: rename the setting for better clarity, it can be a binary path or a custom command
|
||||||
|
self.settings
|
||||||
|
.nginx_binary_path
|
||||||
|
.clone()
|
||||||
|
.unwrap_or_else(|| "nginx".to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn validate_config_path(config_path: &str) -> Result<()> {
|
||||||
|
if !std::path::Path::new(config_path).exists() {
|
||||||
|
anyhow::bail!("Config file not found at path: {}", config_path);
|
||||||
|
}
|
||||||
|
if !std::path::Path::new(config_path).is_file() {
|
||||||
|
anyhow::bail!("Config path is not a file: {}", config_path);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn apply_config_path_to_command_vecs<'a>(
|
||||||
|
command: &'a mut Vec<String>,
|
||||||
|
config_path: &str,
|
||||||
|
) -> Result<&'a mut Vec<String>> {
|
||||||
|
// if given a config path, add it to the end of the command arguments to override the default config path used
|
||||||
|
Self::validate_config_path(config_path)?;
|
||||||
|
let parent_dir = match std::path::Path::new(config_path).parent() {
|
||||||
|
Some(dir) => dir,
|
||||||
|
// return root
|
||||||
|
None => std::path::Path::new("/"),
|
||||||
|
};
|
||||||
|
// set prefix path to the parent directory of the config file to ensure nginx can find all related files (e.g. certs, conf.d, etc.)
|
||||||
|
command.push("-p".to_string());
|
||||||
|
command.push(parent_dir.to_string_lossy().to_string());
|
||||||
|
// add the config file path to the command arguments to override the default config path used by nginx
|
||||||
|
command.push("-c".to_string());
|
||||||
|
command.push(config_path.to_string());
|
||||||
|
Ok(command)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_deployment_dir(&self) -> std::path::PathBuf {
|
||||||
|
std::path::Path::new(&self.settings.nginx_config_path).join("deployments")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_deployment_dir_path(&self, deployment_id: &str) -> std::path::PathBuf {
|
||||||
|
self.get_deployment_dir().join(deployment_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_deployment_config_path(
|
||||||
|
&self,
|
||||||
|
deployment_id: &str,
|
||||||
|
output_path: &str,
|
||||||
|
create_dir_if_not_exists: bool,
|
||||||
|
) -> Result<std::path::PathBuf> {
|
||||||
|
let output_path_obj = std::path::Path::new(output_path);
|
||||||
|
if output_path_obj.is_absolute() {
|
||||||
|
anyhow::bail!("Output path must be a relative path");
|
||||||
|
}
|
||||||
|
if output_path_obj
|
||||||
|
.components()
|
||||||
|
.any(|comp| comp == std::path::Component::ParentDir)
|
||||||
|
{
|
||||||
|
anyhow::bail!("Output path must not contain parent directory traversal");
|
||||||
|
}
|
||||||
|
|
||||||
|
let deployment_config_dir = self.get_deployment_dir_path(deployment_id);
|
||||||
|
let full_path = deployment_config_dir.join(output_path);
|
||||||
|
if create_dir_if_not_exists {
|
||||||
|
if let Some(parent) = full_path.parent() {
|
||||||
|
tokio::fs::create_dir_all(parent).await?;
|
||||||
|
} else {
|
||||||
|
tokio::fs::create_dir_all(&deployment_config_dir).await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(full_path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl NginxHandler for NginxHandlerImpl {
|
||||||
|
async fn reload(&self, config_path: Option<&str>) -> Result<()> {
|
||||||
|
// TODO: add timeout for the command execution
|
||||||
|
let reload_command_str = self.settings.override_nginx_reload_command.clone();
|
||||||
|
let program = match reload_command_str.first() {
|
||||||
|
Some(cmd) => cmd,
|
||||||
|
None => &self.get_nginx_command(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut reload_command_vec = reload_command_str[1..].to_vec();
|
||||||
|
// if given a config path, add it to the end of the command arguments to override the default config path used
|
||||||
|
if let Some(path) = config_path {
|
||||||
|
Self::apply_config_path_to_command_vecs(&mut reload_command_vec, path)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let output = Command::new(program)
|
||||||
|
.args(&reload_command_vec)
|
||||||
|
.output()
|
||||||
|
.await?;
|
||||||
|
if !output.status.success() {
|
||||||
|
let error_info = String::from_utf8_lossy(&output.stderr);
|
||||||
|
anyhow::bail!("Failed to reload nginx: {}", error_info.trim());
|
||||||
|
}
|
||||||
|
let success_info = String::from_utf8_lossy(&output.stdout);
|
||||||
|
debug!("Nginx reloaded successfully: {}", success_info.trim());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn stop(&self) -> Result<()> {
|
||||||
|
let output = Command::new(self.get_nginx_command())
|
||||||
|
.arg("-s")
|
||||||
|
.arg("stop")
|
||||||
|
.output()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
let error_info = String::from_utf8_lossy(&output.stderr);
|
||||||
|
anyhow::bail!("Failed to stop nginx: {}", error_info.trim());
|
||||||
|
}
|
||||||
|
let success_info = String::from_utf8_lossy(&output.stdout);
|
||||||
|
debug!("Nginx stopped successfully: {}", success_info.trim());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn validate(&self, config_path: Option<&str>) -> Result<()> {
|
||||||
|
// TODO: add timeout for the command execution
|
||||||
|
let validate_command_str = self.settings.override_nginx_test_command.clone();
|
||||||
|
let program = match validate_command_str.first() {
|
||||||
|
Some(cmd) => cmd,
|
||||||
|
None => &self.get_nginx_command(),
|
||||||
|
};
|
||||||
|
let mut validate_args = validate_command_str[1..].to_vec();
|
||||||
|
// if given a config path, add it to the end of the command arguments to override the default config path used
|
||||||
|
if let Some(path) = config_path {
|
||||||
|
Self::apply_config_path_to_command_vecs(&mut validate_args, path)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let output = Command::new(program).args(&validate_args).output().await?;
|
||||||
|
if !output.status.success() {
|
||||||
|
let error_info = String::from_utf8_lossy(&output.stderr);
|
||||||
|
anyhow::bail!("Nginx config validation failed: {}", error_info.trim());
|
||||||
|
}
|
||||||
|
let success_info = String::from_utf8_lossy(&output.stdout);
|
||||||
|
debug!("Nginx config validation succeeded: {}", success_info.trim());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_version(&self) -> Result<String> {
|
||||||
|
let output = Command::new(self.get_nginx_command())
|
||||||
|
.arg("-v")
|
||||||
|
.output()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
let error_info = String::from_utf8_lossy(&output.stderr);
|
||||||
|
anyhow::bail!("Failed to get nginx version: {}", error_info.trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
let version_info = String::from_utf8_lossy(&output.stderr);
|
||||||
|
Ok(version_info.trim().to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_status(&self) -> Result<String> {
|
||||||
|
let output = Command::new(self.get_nginx_command())
|
||||||
|
.arg("-t")
|
||||||
|
.output()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
let error_info = String::from_utf8_lossy(&output.stderr);
|
||||||
|
anyhow::bail!("Failed to get nginx status: {}", error_info.trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
let status_info = String::from_utf8_lossy(&output.stderr);
|
||||||
|
Ok(status_info.trim().to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn write_config(
|
||||||
|
&self,
|
||||||
|
deployment_id: &str,
|
||||||
|
config_content: &str,
|
||||||
|
output_path: &str,
|
||||||
|
) -> Result<()> {
|
||||||
|
let full_output_path = self
|
||||||
|
.get_deployment_config_path(deployment_id, output_path, true)
|
||||||
|
.await?;
|
||||||
|
let mut file = tokio::fs::OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.create(true)
|
||||||
|
.truncate(true)
|
||||||
|
.open(full_output_path)
|
||||||
|
.await?;
|
||||||
|
// lock the file for writing to prevent concurrent write issue
|
||||||
|
file.lock_exclusive()?;
|
||||||
|
file.write_all(config_content.as_bytes()).await?;
|
||||||
|
file.unlock()?;
|
||||||
|
file.flush().await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn append_config(
|
||||||
|
&self,
|
||||||
|
deployment_id: &str,
|
||||||
|
config_content: &str,
|
||||||
|
output_path: &str,
|
||||||
|
) -> Result<()> {
|
||||||
|
let full_output_path = self
|
||||||
|
.get_deployment_config_path(deployment_id, output_path, true)
|
||||||
|
.await?;
|
||||||
|
let mut file = tokio::fs::OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.create(true)
|
||||||
|
.append(true)
|
||||||
|
.open(full_output_path)
|
||||||
|
.await?;
|
||||||
|
// lock the file for writing to prevent concurrent write issue
|
||||||
|
file.lock_exclusive()?;
|
||||||
|
file.write_all(config_content.as_bytes()).await?;
|
||||||
|
file.unlock()?;
|
||||||
|
file.flush().await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn cleanup_config(&self, n: usize) -> Result<()> {
|
||||||
|
let deployment_dir = self.get_deployment_dir();
|
||||||
|
// loop through all files in the deployment dir and delete them
|
||||||
|
let mut entries = tokio::fs::read_dir(&deployment_dir).await?;
|
||||||
|
let mut deployment_ids = Vec::new();
|
||||||
|
while let Some(entry) = entries.next_entry().await? {
|
||||||
|
let file_type = entry.file_type().await?;
|
||||||
|
if file_type.is_dir()
|
||||||
|
&& let Some(deployment_id) = entry.file_name().to_str()
|
||||||
|
{
|
||||||
|
deployment_ids.push(deployment_id.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// sort the deployment ids by modified time in descending order and keep the latest n deployments, delete the rest
|
||||||
|
deployment_ids.sort_by_key(|id| {
|
||||||
|
let path = self.get_deployment_dir_path(id);
|
||||||
|
std::fs::metadata(path)
|
||||||
|
.and_then(|meta| meta.modified())
|
||||||
|
.unwrap_or(std::time::SystemTime::UNIX_EPOCH)
|
||||||
|
});
|
||||||
|
for deployment_id in deployment_ids.into_iter().skip(n) {
|
||||||
|
let path = self.get_deployment_dir_path(&deployment_id);
|
||||||
|
// ensure path is within the deplyment and nginx directory to prevent accidental deletion of other files
|
||||||
|
if !path.starts_with(&deployment_dir)
|
||||||
|
|| !path.starts_with(&self.settings.nginx_config_path)
|
||||||
|
{
|
||||||
|
warn!(
|
||||||
|
"Skipping deletion of path outside of deployment or nginx config directory: {:?}",
|
||||||
|
path
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
tokio::fs::remove_dir_all(path).await?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[allow(clippy::expect_used)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use anyhow::Result;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use tempfile::TempDir;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn write_and_append_config_roundtrip() -> Result<()> {
|
||||||
|
let temp = TempDir::new()?;
|
||||||
|
let settings = NginxSettings {
|
||||||
|
nginx_config_path: temp.path().to_string_lossy().to_string(),
|
||||||
|
nginx_binary_path: None,
|
||||||
|
override_nginx_reload_command: vec![],
|
||||||
|
override_nginx_test_command: vec![],
|
||||||
|
nginx_reload_timeout_seconds: 1,
|
||||||
|
nginx_test_timeout_seconds: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
let handler = NginxHandlerImpl::new(Arc::new(settings));
|
||||||
|
|
||||||
|
handler
|
||||||
|
.write_config("deployment1", "hello", "conf/nginx.conf")
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let full_path = temp
|
||||||
|
.path()
|
||||||
|
.join("deployments")
|
||||||
|
.join("deployment1")
|
||||||
|
.join("conf/nginx.conf");
|
||||||
|
|
||||||
|
let content = tokio::fs::read_to_string(&full_path).await?;
|
||||||
|
assert_eq!(content, "hello");
|
||||||
|
|
||||||
|
handler
|
||||||
|
.append_config("deployment1", " world", "conf/nginx.conf")
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let content = tokio::fs::read_to_string(&full_path).await?;
|
||||||
|
assert_eq!(content, "hello world");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn write_config_rejects_absolute_and_traversal_paths() -> Result<()> {
|
||||||
|
let temp = TempDir::new()?;
|
||||||
|
let settings = NginxSettings {
|
||||||
|
nginx_config_path: temp.path().to_string_lossy().to_string(),
|
||||||
|
nginx_binary_path: None,
|
||||||
|
override_nginx_reload_command: vec![],
|
||||||
|
override_nginx_test_command: vec![],
|
||||||
|
nginx_reload_timeout_seconds: 1,
|
||||||
|
nginx_test_timeout_seconds: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
let handler = NginxHandlerImpl::new(Arc::new(settings));
|
||||||
|
|
||||||
|
let err = handler
|
||||||
|
.write_config("d", "x", "/absolute/path.conf")
|
||||||
|
.await
|
||||||
|
.err();
|
||||||
|
assert!(err.is_some());
|
||||||
|
|
||||||
|
let err = handler.write_config("d", "x", "../escape.conf").await.err();
|
||||||
|
assert!(err.is_some());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn validate_config_path_checks_file_exists_and_is_file() {
|
||||||
|
// missing file
|
||||||
|
let res = NginxHandlerImpl::validate_config_path("/this/path/does/not/exist.conf");
|
||||||
|
assert!(res.is_err());
|
||||||
|
|
||||||
|
// create a temp dir and ensure a directory is rejected
|
||||||
|
let temp = TempDir::new().expect("Failed to create temp dir");
|
||||||
|
let dir_path = temp.path();
|
||||||
|
let res = NginxHandlerImpl::validate_config_path(dir_path.to_string_lossy().as_ref());
|
||||||
|
assert!(res.is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn apply_config_path_to_command_vecs_appends_prefix_and_config() -> Result<()> {
|
||||||
|
let temp = TempDir::new()?;
|
||||||
|
let cfg_file = temp.path().join("nginx.conf");
|
||||||
|
tokio::fs::write(&cfg_file, b"data").await?;
|
||||||
|
|
||||||
|
let mut args: Vec<String> = vec!["base".to_string()];
|
||||||
|
let result = NginxHandlerImpl::apply_config_path_to_command_vecs(
|
||||||
|
&mut args,
|
||||||
|
&cfg_file.to_string_lossy(),
|
||||||
|
);
|
||||||
|
assert!(result.is_ok());
|
||||||
|
let args = result.expect("Failed to apply config path to command vecs");
|
||||||
|
// expect -p <parent_dir> -c <config>
|
||||||
|
assert!(args.contains(&"-p".to_string()));
|
||||||
|
assert!(args.contains(&"-c".to_string()));
|
||||||
|
assert!(args.contains(&cfg_file.to_string_lossy().to_string()));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn get_deployment_config_path_create_flag_behaviour() -> Result<()> {
|
||||||
|
let temp = TempDir::new()?;
|
||||||
|
let settings = NginxSettings {
|
||||||
|
nginx_config_path: temp.path().to_string_lossy().to_string(),
|
||||||
|
nginx_binary_path: None,
|
||||||
|
override_nginx_reload_command: vec![],
|
||||||
|
override_nginx_test_command: vec![],
|
||||||
|
nginx_reload_timeout_seconds: 1,
|
||||||
|
nginx_test_timeout_seconds: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
let handler = NginxHandlerImpl::new(Arc::new(settings));
|
||||||
|
|
||||||
|
// when create_dir_if_not_exists = false, directory shouldn't be created
|
||||||
|
let path = handler
|
||||||
|
.get_deployment_config_path("did", "conf/nginx.conf", false)
|
||||||
|
.await?;
|
||||||
|
assert!(
|
||||||
|
!path
|
||||||
|
.parent()
|
||||||
|
.expect("Failed to get parent directory of deployment config path")
|
||||||
|
.exists()
|
||||||
|
);
|
||||||
|
|
||||||
|
// when create_dir_if_not_exists = true, directory should be created
|
||||||
|
let path = handler
|
||||||
|
.get_deployment_config_path("did", "conf/nginx.conf", true)
|
||||||
|
.await?;
|
||||||
|
assert!(
|
||||||
|
path.parent()
|
||||||
|
.expect("Failed to get parent directory of deployment config path")
|
||||||
|
.exists()
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn cleanup_config_deletes_expected_deployments() -> Result<()> {
|
||||||
|
let temp = TempDir::new()?;
|
||||||
|
let settings = NginxSettings {
|
||||||
|
nginx_config_path: temp.path().to_string_lossy().to_string(),
|
||||||
|
nginx_binary_path: None,
|
||||||
|
override_nginx_reload_command: vec![],
|
||||||
|
override_nginx_test_command: vec![],
|
||||||
|
nginx_reload_timeout_seconds: 1,
|
||||||
|
nginx_test_timeout_seconds: 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
let handler = NginxHandlerImpl::new(Arc::new(settings));
|
||||||
|
let base = temp.path().join("deployments");
|
||||||
|
|
||||||
|
// create three deployments sequentially so mtimes differ
|
||||||
|
for id in &["d1", "d2", "d3"] {
|
||||||
|
let p = base.join(id);
|
||||||
|
std::fs::create_dir_all(&p)?;
|
||||||
|
std::fs::write(p.join("file"), b"x")?;
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(500));
|
||||||
|
}
|
||||||
|
|
||||||
|
// call cleanup keeping 1; current implementation keeps the oldest n, so expect only d1 remains
|
||||||
|
handler.cleanup_config(1).await?;
|
||||||
|
|
||||||
|
let mut exists = vec![];
|
||||||
|
for id in &["d1", "d2", "d3"] {
|
||||||
|
exists.push((id.to_string(), base.join(id).exists()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// d1 should remain, others removed (matches current implementation behavior)
|
||||||
|
assert!(exists.iter().find(|(id, e)| id == "d1" && *e).is_some());
|
||||||
|
assert!(exists.iter().find(|(id, e)| id == "d2" && !*e).is_some());
|
||||||
|
assert!(exists.iter().find(|(id, e)| id == "d3" && !*e).is_some());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -84,7 +84,13 @@ time = "0.3"
|
|||||||
|
|
||||||
# Cert handling
|
# Cert handling
|
||||||
zip = { workspace = true }
|
zip = { workspace = true }
|
||||||
|
rust-embed = { version = "8.11.0", features = [] }
|
||||||
|
mime_guess = "2.0.5"
|
||||||
|
axum-test = "20.0.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tokio-test.workspace = true
|
tokio-test.workspace = true
|
||||||
mockall.workspace = true
|
mockall.workspace = true
|
||||||
|
|
||||||
|
[features]
|
||||||
|
dev-tools = ["axum/macros"]
|
||||||
|
|||||||
1
apps/nxmesh-master/frontend-dist
Symbolic link
1
apps/nxmesh-master/frontend-dist
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../nxmesh-frontend/dist/
|
||||||
@@ -6,6 +6,7 @@ use nxmesh_proto::{
|
|||||||
};
|
};
|
||||||
use sea_orm::{ColumnTrait, DatabaseConnection, EntityTrait, QueryFilter};
|
use sea_orm::{ColumnTrait, DatabaseConnection, EntityTrait, QueryFilter};
|
||||||
use tonic::transport::Server;
|
use tonic::transport::Server;
|
||||||
|
use tracing::info;
|
||||||
|
|
||||||
use crate::{db::entities::public_key_revocations, service::agent::AgentServerService};
|
use crate::{db::entities::public_key_revocations, service::agent::AgentServerService};
|
||||||
|
|
||||||
@@ -69,7 +70,14 @@ impl AgentConnectorTrait for SshAgentConnector {
|
|||||||
.layer(ssh_interceptor)
|
.layer(ssh_interceptor)
|
||||||
.add_service(agent_server_service);
|
.add_service(agent_server_service);
|
||||||
|
|
||||||
router.serve(addr).await?;
|
info!("SSH Agent gRPC server is listening on {}", addr);
|
||||||
|
router
|
||||||
|
.serve(addr)
|
||||||
|
.await
|
||||||
|
.inspect(|_| info!("SSH Agent gRPC server stopped gracefully."))
|
||||||
|
.inspect_err(|e| {
|
||||||
|
tracing::error!("SSH Agent gRPC server failed: {}", e);
|
||||||
|
})?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ mod cli;
|
|||||||
mod config;
|
mod config;
|
||||||
mod connector;
|
mod connector;
|
||||||
mod db;
|
mod db;
|
||||||
|
mod routes;
|
||||||
mod service;
|
mod service;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
|||||||
160
apps/nxmesh-master/src/routes/frontend/mod.rs
Normal file
160
apps/nxmesh-master/src/routes/frontend/mod.rs
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
use axum::{Router, response::IntoResponse};
|
||||||
|
use tracing::error;
|
||||||
|
|
||||||
|
// In development, build the frontend from the source directory, the soft link will handle the path resolution
|
||||||
|
// In deployment, pre-build the frontend and replace the frontend-dist folder with the built assets, the rust-embed will handle the embedding and path resolution
|
||||||
|
#[derive(rust_embed::Embed)]
|
||||||
|
#[folder = "./frontend-dist/"]
|
||||||
|
struct FrontendAssets;
|
||||||
|
|
||||||
|
const INDEX_HTML: &str = "index.html";
|
||||||
|
|
||||||
|
pub async fn get_router() -> Router {
|
||||||
|
Router::new()
|
||||||
|
.route(
|
||||||
|
"/",
|
||||||
|
axum::routing::get(get_fallback_handler)
|
||||||
|
.head(get_fallback_handler)
|
||||||
|
.options(get_fallback_handler),
|
||||||
|
)
|
||||||
|
.route(
|
||||||
|
"/{*path}",
|
||||||
|
axum::routing::get(get_file_handler)
|
||||||
|
.head(get_file_handler)
|
||||||
|
.options(get_file_handler),
|
||||||
|
)
|
||||||
|
//
|
||||||
|
.fallback(get_fallback_handler().await)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_fallback_handler() -> Result<axum::response::Html<Vec<u8>>, axum::http::StatusCode>
|
||||||
|
{
|
||||||
|
let index_html = get_index_html();
|
||||||
|
match index_html {
|
||||||
|
Some(html) => Ok(axum::response::Html(html)),
|
||||||
|
None => Err(axum::http::StatusCode::NOT_FOUND),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_index_html() -> Option<Vec<u8>> {
|
||||||
|
FrontendAssets::get(INDEX_HTML).map(|asset| asset.data.as_ref().to_owned())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_file_handler(
|
||||||
|
axum::extract::Path(path): axum::extract::Path<String>,
|
||||||
|
) -> Result<axum::response::Response, axum::http::StatusCode> {
|
||||||
|
let file_path = if path.is_empty() {
|
||||||
|
INDEX_HTML.to_string()
|
||||||
|
} else {
|
||||||
|
path
|
||||||
|
};
|
||||||
|
|
||||||
|
match FrontendAssets::get(&file_path) {
|
||||||
|
Some(asset) => {
|
||||||
|
let content_type = mime_guess::from_path(&file_path).first_or_octet_stream();
|
||||||
|
let response = axum::response::Response::builder()
|
||||||
|
.header(axum::http::header::CONTENT_TYPE, content_type.as_ref())
|
||||||
|
.body(asset.data.into_owned().into())
|
||||||
|
.map_err(|e| {
|
||||||
|
error!("Failed to build response for {}: {}", file_path, e);
|
||||||
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR
|
||||||
|
})?;
|
||||||
|
Ok(response)
|
||||||
|
}
|
||||||
|
// return index.html for any file not found to support client-side routing in the frontend
|
||||||
|
None => get_fallback_handler()
|
||||||
|
.await
|
||||||
|
.map(|html| html.into_response()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[allow(clippy::expect_used)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_asset() {
|
||||||
|
// list all embedded assets for debugging
|
||||||
|
let assets = FrontendAssets::iter().collect::<Vec<_>>();
|
||||||
|
println!("Embedded assets: {:?}", assets);
|
||||||
|
assert!(
|
||||||
|
!assets.is_empty(),
|
||||||
|
"Expected to find embedded assets, but found none"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_get_index_html() {
|
||||||
|
let index_html = get_index_html();
|
||||||
|
assert!(
|
||||||
|
index_html.is_some(),
|
||||||
|
"Expected to find index.html in embedded assets"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_get_file_handler_existing_file() {
|
||||||
|
let response = get_file_handler(axum::extract::Path("index.html".to_string())).await;
|
||||||
|
assert!(
|
||||||
|
response.is_ok(),
|
||||||
|
"Expected to successfully retrieve index.html"
|
||||||
|
);
|
||||||
|
let response = response.expect("Expected response to be Ok");
|
||||||
|
assert_eq!(response.status(), axum::http::StatusCode::OK);
|
||||||
|
assert!(
|
||||||
|
response
|
||||||
|
.headers()
|
||||||
|
.get(axum::http::header::CONTENT_TYPE)
|
||||||
|
.map(|ct| ct.to_str().unwrap_or(""))
|
||||||
|
.expect("Content-Type header should be present")
|
||||||
|
.starts_with("text/html")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_get_file_handler_nonexistent_file() {
|
||||||
|
let response = get_file_handler(axum::extract::Path("nonexistent.txt".to_string())).await;
|
||||||
|
assert!(
|
||||||
|
response.is_ok(),
|
||||||
|
"Expected to fallback to index.html for nonexistent file"
|
||||||
|
);
|
||||||
|
let response = response.expect("Expected response to be Ok");
|
||||||
|
assert_eq!(response.status(), axum::http::StatusCode::OK);
|
||||||
|
assert!(
|
||||||
|
response
|
||||||
|
.headers()
|
||||||
|
.get(axum::http::header::CONTENT_TYPE)
|
||||||
|
.map(|ct| ct.to_str().unwrap_or(""))
|
||||||
|
.expect("Content-Type header should be present")
|
||||||
|
.starts_with("text/html")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod axum_tests {
|
||||||
|
use super::*;
|
||||||
|
use axum_test::TestServer;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_should_return_index_html_for_root_path() {
|
||||||
|
let router = get_router().await;
|
||||||
|
let server = TestServer::new(router);
|
||||||
|
let response = server.get("/").await;
|
||||||
|
assert_eq!(response.status_code(), 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_should_return_index_html_for_nonexistent_path() {
|
||||||
|
let router = get_router().await;
|
||||||
|
let server = TestServer::new(router);
|
||||||
|
let fallback_response = server.get("/nonexistent").await;
|
||||||
|
assert_eq!(fallback_response.status_code(), 200);
|
||||||
|
|
||||||
|
let index_response = server.get("/").await;
|
||||||
|
assert_eq!(index_response.status_code(), 200);
|
||||||
|
|
||||||
|
assert_eq!(fallback_response.text(), index_response.text());
|
||||||
|
}
|
||||||
|
}
|
||||||
36
apps/nxmesh-master/src/routes/mod.rs
Normal file
36
apps/nxmesh-master/src/routes/mod.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
use axum::Router;
|
||||||
|
|
||||||
|
mod frontend;
|
||||||
|
|
||||||
|
pub async fn get_root_router() -> Router {
|
||||||
|
Router::new()
|
||||||
|
.merge(frontend::get_router().await)
|
||||||
|
.fallback(frontend::get_fallback_handler().await)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use axum_test::TestServer;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_should_return_index_html_for_root_path() {
|
||||||
|
let router = get_root_router().await;
|
||||||
|
let server = TestServer::new(router);
|
||||||
|
let response = server.get("/").await;
|
||||||
|
assert_eq!(response.status_code(), 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_should_return_index_html_for_nonexistent_path() {
|
||||||
|
let router = get_root_router().await;
|
||||||
|
let server = TestServer::new(router);
|
||||||
|
let fallback_response = server.get("/nonexistent").await;
|
||||||
|
assert_eq!(fallback_response.status_code(), 200);
|
||||||
|
|
||||||
|
let index_response = server.get("/").await;
|
||||||
|
assert_eq!(index_response.status_code(), 200);
|
||||||
|
|
||||||
|
assert_eq!(fallback_response.text(), index_response.text());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
use std::sync::Arc;
|
use std::{net::ToSocketAddrs, sync::Arc};
|
||||||
|
|
||||||
|
use tracing::info;
|
||||||
|
|
||||||
use crate::{connector::agent::AgentConnectorTrait, service::certificate::CertificateService};
|
use crate::{connector::agent::AgentConnectorTrait, service::certificate::CertificateService};
|
||||||
|
|
||||||
@@ -26,15 +28,38 @@ pub async fn start_master_server(
|
|||||||
println!("Certificate generated and stored successfully.");
|
println!("Certificate generated and stored successfully.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize agent connector
|
let ssh_connector = crate::connector::agent::ssh::SshAgentConnector::new(settings.clone())?;
|
||||||
let mut agent_connector = crate::connector::agent::AgentConnector::new(Box::new(
|
let cert_service_for_agent = cert_service.clone();
|
||||||
crate::connector::agent::ssh::SshAgentConnector::new(settings.clone())?,
|
let settings_for_agent = settings.clone();
|
||||||
));
|
let connection_for_agent = db_connection.clone();
|
||||||
|
|
||||||
// Start the agent server
|
tokio::spawn(async move {
|
||||||
agent_connector
|
let mut connector = ssh_connector;
|
||||||
.start_server(&settings, cert_service, db_connection)
|
tracing::info!("Starting agent server...");
|
||||||
.await?;
|
if let Err(e) = connector
|
||||||
|
.start_server(
|
||||||
|
&settings_for_agent,
|
||||||
|
cert_service_for_agent,
|
||||||
|
connection_for_agent,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
tracing::error!("Agent server failed: {}", e);
|
||||||
|
} else {
|
||||||
|
tracing::info!("Agent server stopped.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let axum_router = crate::routes::get_root_router().await;
|
||||||
|
|
||||||
|
// Start the HTTP server
|
||||||
|
let addr = format!("{}:{}", settings.server.bind_address, settings.server.port)
|
||||||
|
.to_socket_addrs()?
|
||||||
|
.next()
|
||||||
|
.ok_or("Invalid bind address")?;
|
||||||
|
let listener = tokio::net::TcpListener::bind(addr).await?;
|
||||||
|
info!("Web/API server is listening on {}", addr);
|
||||||
|
axum::serve(listener, axum_router).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user