refactor: rename HOST_* env vars to SLHAF_HUB_* across CLI/TUI, security, docs, and compose

This commit is contained in:
2026-02-25 13:59:27 +08:00
parent ff012c3b9a
commit 757af8d89b
6 changed files with 20 additions and 20 deletions

View File

@@ -37,15 +37,15 @@ cd slhaf-hub
docker build -t slhaf-hub:latest . docker build -t slhaf-hub:latest .
docker run --rm -p 8080:8080 \ docker run --rm -p 8080:8080 \
-v "$(pwd)/scripts:/app/scripts" \ -v "$(pwd)/scripts:/app/scripts" \
-e HOST_API_TOKEN=your-token \ -e SLHAF_HUB_TOKEN=your-token \
-e MAX_RUN_CONCURRENCY=8 \ -e MAX_RUN_CONCURRENCY=8 \
slhaf-hub:latest slhaf-hub:latest
``` ```
#### 3) Run with Docker Compose #### 3) Run with Docker Compose
```bash ```bash
# optional: export HOST_API_TOKEN=your-token # optional: export SLHAF_HUB_TOKEN=your-token
# optional: export HOST_PORT=8080 # optional: export SLHAF_HUB_PORT=8080
# optional: export MAX_RUN_CONCURRENCY=8 # optional: export MAX_RUN_CONCURRENCY=8
docker compose up -d --build docker compose up -d --build
``` ```
@@ -79,7 +79,7 @@ Auth headers:
- `X-Host-Token: <token>` - `X-Host-Token: <token>`
Token source priority: Token source priority:
1. `HOST_API_TOKEN` env var 1. `SLHAF_HUB_TOKEN` env var
2. `scripts/.host-api-token` 2. `scripts/.host-api-token`
3. Auto-generated token saved to `scripts/.host-api-token` 3. Auto-generated token saved to `scripts/.host-api-token`

View File

@@ -37,15 +37,15 @@ cd slhaf-hub
docker build -t slhaf-hub:latest . docker build -t slhaf-hub:latest .
docker run --rm -p 8080:8080 \ docker run --rm -p 8080:8080 \
-v "$(pwd)/scripts:/app/scripts" \ -v "$(pwd)/scripts:/app/scripts" \
-e HOST_API_TOKEN=your-token \ -e SLHAF_HUB_TOKEN=your-token \
-e MAX_RUN_CONCURRENCY=8 \ -e MAX_RUN_CONCURRENCY=8 \
slhaf-hub:latest slhaf-hub:latest
``` ```
#### 3) Docker Compose 启动 #### 3) Docker Compose 启动
```bash ```bash
# 可选export HOST_API_TOKEN=your-token # 可选export SLHAF_HUB_TOKEN=your-token
# 可选export HOST_PORT=8080 # 可选export SLHAF_HUB_PORT=8080
# 可选export MAX_RUN_CONCURRENCY=8 # 可选export MAX_RUN_CONCURRENCY=8
docker compose up -d --build docker compose up -d --build
``` ```
@@ -79,7 +79,7 @@ CLI/TUI 环境变量:
- `X-Host-Token: <token>` - `X-Host-Token: <token>`
Token 来源优先级: Token 来源优先级:
1. 环境变量 `HOST_API_TOKEN` 1. 环境变量 `SLHAF_HUB_TOKEN`
2. `scripts/.host-api-token` 2. `scripts/.host-api-token`
3. 自动生成并写入 `scripts/.host-api-token` 3. 自动生成并写入 `scripts/.host-api-token`

View File

@@ -10,9 +10,9 @@ services:
container_name: slhaf-hub container_name: slhaf-hub
restart: unless-stopped restart: unless-stopped
ports: ports:
- "${HOST_PORT:-8080}:8080" - "${SLHAF_HUB_PORT:-8080}:8080"
environment: environment:
HOST_API_TOKEN: ${HOST_API_TOKEN:-} SLHAF_HUB_TOKEN: ${SLHAF_HUB_TOKEN:-}
MAX_RUN_CONCURRENCY: ${MAX_RUN_CONCURRENCY:-} MAX_RUN_CONCURRENCY: ${MAX_RUN_CONCURRENCY:-}
volumes: volumes:
- ./scripts:/app/scripts - ./scripts:/app/scripts

View File

@@ -8,7 +8,7 @@ import io.ktor.server.response.respondText
import java.io.File import java.io.File
import java.security.SecureRandom import java.security.SecureRandom
private const val ENV_API_TOKEN = "HOST_API_TOKEN" private const val ENV_API_TOKEN = "SLHAF_HUB_TOKEN"
private const val TOKEN_FILE_NAME = ".host-api-token" private const val TOKEN_FILE_NAME = ".host-api-token"
private const val SUBTOKEN_FILE_NAME = ".host-subtokens.db" private const val SUBTOKEN_FILE_NAME = ".host-subtokens.db"
private const val ALT_TOKEN_HEADER = "X-Host-Token" private const val ALT_TOKEN_HEADER = "X-Host-Token"

View File

@@ -9,8 +9,8 @@ import java.net.http.HttpResponse
import java.nio.charset.StandardCharsets import java.nio.charset.StandardCharsets
import kotlin.system.exitProcess import kotlin.system.exitProcess
val ENV_API_BASE_URL = "HOST_API_BASE_URL" val ENV_API_BASE_URL = "SLHAF_HUB_BASE_URL"
val ENV_API_TOKEN = "HOST_API_TOKEN" val ENV_API_TOKEN = "SLHAF_HUB_TOKEN"
data class GlobalOptions( data class GlobalOptions(
val baseUrl: String, val baseUrl: String,
@@ -30,9 +30,9 @@ Usage:
kotlin slhaf-hub-cli.kts [global options] <command> [command options] kotlin slhaf-hub-cli.kts [global options] <command> [command options]
Global options: Global options:
--base-url=<url> Default: HOST_API_BASE_URL or http://127.0.0.1:8080 --base-url=<url> Default: SLHAF_HUB_BASE_URL or http://127.0.0.1:8080
--token=<token> Authorization token --token=<token> Authorization token
--token-file=<path> Load token from file (fallback: HOST_API_TOKEN env) --token-file=<path> Load token from file (fallback: SLHAF_HUB_TOKEN env)
Commands: Commands:
health health

View File

@@ -54,8 +54,8 @@ private val YELLOW = "\u001b[33m"
private val RED = "\u001b[31m" private val RED = "\u001b[31m"
private val BG_BLUE = "\u001b[44m" private val BG_BLUE = "\u001b[44m"
private val FG_BLACK = "\u001b[30m" private val FG_BLACK = "\u001b[30m"
val ENV_API_BASE_URL = "HOST_API_BASE_URL" val ENV_API_BASE_URL = "SLHAF_HUB_BASE_URL"
val ENV_API_TOKEN = "HOST_API_TOKEN" val ENV_API_TOKEN = "SLHAF_HUB_TOKEN"
private fun ok(text: String) = "$GREEN$text$RESET" private fun ok(text: String) = "$GREEN$text$RESET"
private fun warn(text: String) = "$YELLOW$text$RESET" private fun warn(text: String) = "$YELLOW$text$RESET"
@@ -81,8 +81,8 @@ Keys:
q Quit q Quit
Env fallback: Env fallback:
HOST_API_BASE_URL SLHAF_HUB_BASE_URL
HOST_API_TOKEN SLHAF_HUB_TOKEN
""".trimIndent() """.trimIndent()
fun parseOptions(args: List<String>): Options { fun parseOptions(args: List<String>): Options {
@@ -113,7 +113,7 @@ fun readToken(options: Options): String {
return file.readText().trim() return file.readText().trim()
} }
return System.getenv(ENV_API_TOKEN)?.trim() return System.getenv(ENV_API_TOKEN)?.trim()
?: error("Missing token. Use --token or --token-file or HOST_API_TOKEN") ?: error("Missing token. Use --token or --token-file or SLHAF_HUB_TOKEN")
} }
fun encode(value: String): String = URLEncoder.encode(value, StandardCharsets.UTF_8) fun encode(value: String): String = URLEncoder.encode(value, StandardCharsets.UTF_8)