Stage 7: configuration view — backend service, routers, tests, and frontend
- config_service.py: read/write jail config via asyncio.gather, global settings, in-process regex validation, log preview via _read_tail_lines - server_service.py: read/write server settings, flush logs - config router: 9 endpoints for jail/global config, regex-test, logpath management, log preview - server router: GET/PUT settings, POST flush-logs - models/config.py expanded with JailConfig, GlobalConfigUpdate, LogPreview* models - 285 tests pass (68 new), ruff clean, mypy clean (44 files) - Frontend: types/config.ts, api/config.ts, hooks/useConfig.ts, ConfigPage.tsx full implementation (Jails accordion editor, Global config, Server settings, Regex Tester with preview) - Fixed pre-existing frontend lint: JSX.Element → React.JSX.Element (10 files), void/promise patterns in useServerStatus + useJails, no-misused-spread in client.ts, eslint.config.ts self-excluded
This commit is contained in:
121
frontend/src/api/config.ts
Normal file
121
frontend/src/api/config.ts
Normal file
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* API functions for the configuration and server settings endpoints.
|
||||
*/
|
||||
|
||||
import { get, post, put } from "./client";
|
||||
import { ENDPOINTS } from "./endpoints";
|
||||
import type {
|
||||
AddLogPathRequest,
|
||||
GlobalConfig,
|
||||
GlobalConfigUpdate,
|
||||
JailConfigListResponse,
|
||||
JailConfigResponse,
|
||||
JailConfigUpdate,
|
||||
LogPreviewRequest,
|
||||
LogPreviewResponse,
|
||||
RegexTestRequest,
|
||||
RegexTestResponse,
|
||||
ServerSettingsResponse,
|
||||
ServerSettingsUpdate,
|
||||
} from "../types/config";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Jail configuration
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function fetchJailConfigs(
|
||||
): Promise<JailConfigListResponse> {
|
||||
return get<JailConfigListResponse>(ENDPOINTS.configJails);
|
||||
}
|
||||
|
||||
export async function fetchJailConfig(
|
||||
name: string
|
||||
): Promise<JailConfigResponse> {
|
||||
return get<JailConfigResponse>(ENDPOINTS.configJail(name));
|
||||
}
|
||||
|
||||
export async function updateJailConfig(
|
||||
name: string,
|
||||
update: JailConfigUpdate
|
||||
): Promise<void> {
|
||||
await put<undefined>(ENDPOINTS.configJail(name), update);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Global configuration
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function fetchGlobalConfig(
|
||||
): Promise<GlobalConfig> {
|
||||
return get<GlobalConfig>(ENDPOINTS.configGlobal);
|
||||
}
|
||||
|
||||
export async function updateGlobalConfig(
|
||||
update: GlobalConfigUpdate
|
||||
): Promise<void> {
|
||||
await put<undefined>(ENDPOINTS.configGlobal, update);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Reload
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function reloadConfig(
|
||||
): Promise<void> {
|
||||
await post<undefined>(ENDPOINTS.configReload, undefined);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Regex tester
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function testRegex(
|
||||
req: RegexTestRequest
|
||||
): Promise<RegexTestResponse> {
|
||||
return post<RegexTestResponse>(ENDPOINTS.configRegexTest, req);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Log path management
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function addLogPath(
|
||||
jailName: string,
|
||||
req: AddLogPathRequest
|
||||
): Promise<void> {
|
||||
await post<undefined>(ENDPOINTS.configJailLogPath(jailName), req);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Log preview
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function previewLog(
|
||||
req: LogPreviewRequest
|
||||
): Promise<LogPreviewResponse> {
|
||||
return post<LogPreviewResponse>(ENDPOINTS.configPreviewLog, req);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Server settings
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function fetchServerSettings(
|
||||
): Promise<ServerSettingsResponse> {
|
||||
return get<ServerSettingsResponse>(ENDPOINTS.serverSettings);
|
||||
}
|
||||
|
||||
export async function updateServerSettings(
|
||||
update: ServerSettingsUpdate
|
||||
): Promise<void> {
|
||||
await put<undefined>(ENDPOINTS.serverSettings, update);
|
||||
}
|
||||
|
||||
export async function flushLogs(
|
||||
): Promise<string> {
|
||||
const resp = await post<{ message: string }>(
|
||||
ENDPOINTS.serverFlushLogs,
|
||||
undefined,
|
||||
);
|
||||
return resp.message;
|
||||
}
|
||||
Reference in New Issue
Block a user