From 50cee580de9326109dbe0d65bb9bd3bec19cf5f4 Mon Sep 17 00:00:00 2001 From: Fergus Molloy Date: Fri, 25 Jul 2025 00:39:26 +0100 Subject: [PATCH] make shutdown endpoint default --- .gitea/workflows/backend.yaml | 4 ++-- backend/Cargo.toml | 3 ++- backend/Justfile | 6 +++--- backend/readme.md | 7 ++++--- backend/scripts/test.sh | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.gitea/workflows/backend.yaml b/.gitea/workflows/backend.yaml index 7afbdcb..8177b32 100644 --- a/.gitea/workflows/backend.yaml +++ b/.gitea/workflows/backend.yaml @@ -55,8 +55,8 @@ jobs: ~/.cargo/git backend/target key: ${{ runner.os }}-cargo-test-${{ hashFiles('backend/Cargo.lock') }} - - name: Build Binary with Shutdown - run: cargo build --features shutdown --bin nuchat + - name: Build Binary + run: cargo build --locked --bin nuchat - name: Run Tests run: ./scripts/test.sh - name: Upload Test Logs diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 1ffe93c..88c12ce 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -28,5 +28,6 @@ path = "src/main.rs" name ="nuchat" [features] -default = [] +default = [ "shutdown" ] +all = ["shutdown"] shutdown = [] diff --git a/backend/Justfile b/backend/Justfile index 090be26..9ef53a9 100644 --- a/backend/Justfile +++ b/backend/Justfile @@ -1,11 +1,11 @@ build: - cargo build --features shutdown + cargo build run: - cargo run --features shutdown + cargo run start: - cargo run --features shutdown 2>&1 > logs/nuchat.log + cargo run 2>&1 > logs/nuchat.log test: ./scripts/test.sh diff --git a/backend/readme.md b/backend/readme.md index 21d3f35..d96d176 100644 --- a/backend/readme.md +++ b/backend/readme.md @@ -1,9 +1,10 @@ # Backend -Generate random secret using. This secret will be used to authenticate users on all `/admin` routes +Generate random secret using openssl. This secret will be used to authenticate users on all `/admin` routes. +If no secret is given then no authentication will be required ```bash -ADMIN_SECRET=$(openssl rand --base64 32) +nuchat --admin-secret $(openssl rand --base64 32) ``` ## Features @@ -11,5 +12,5 @@ ADMIN_SECRET=$(openssl rand --base64 32) ### shutdown this feature enables an endpoint that allows you to shutdown the server. -**WARNING**: If the `ADMIN_SECRET` env var is not set then this endpoint is completely exposed and allows anyone to shutdown the server. +**WARNING**: If the `admin-secret` flag is not set then this endpoint is completely exposed and allows anyone to shutdown the server. diff --git a/backend/scripts/test.sh b/backend/scripts/test.sh index 312dbae..9ac318a 100755 --- a/backend/scripts/test.sh +++ b/backend/scripts/test.sh @@ -14,7 +14,7 @@ fi curl -s -X POST localhost:7001/admin/shutdown 2>&1 > /dev/null # start server -cargo run --features shutdown -- --port 7001 2>&1 > logs/nuchat.log & +cargo run -- --port 7001 2>&1 > logs/nuchat.log & # run tests cargo nextest run --color=always 2>&1 | tee logs/test-output.log