Narrow jail config types with explicit union values

This commit is contained in:
2026-04-21 19:39:36 +02:00
parent fef8f60ee2
commit 4c313af1c5
5 changed files with 46 additions and 32 deletions

View File

@@ -39,6 +39,10 @@ export interface BantimeEscalationUpdate {
// Jail Configuration
// ---------------------------------------------------------------------------
export type DNSMode = "yes" | "warn" | "no" | "raw";
export type LogEncoding = "auto" | "ascii" | "utf-8" | "UTF-8" | "latin-1";
export type BackendType = "auto" | "polling" | "pyinotify" | "systemd" | "gamin";
export interface JailConfig {
name: string;
ban_time: number;
@@ -48,10 +52,10 @@ export interface JailConfig {
ignore_regex: string[];
log_paths: string[];
date_pattern: string | null;
log_encoding: string;
backend: string;
log_encoding: LogEncoding;
backend: BackendType;
/** DNS look-up mode reported by fail2ban: "yes" | "warn" | "no" | "raw". */
use_dns: string;
use_dns: DNSMode;
/** Prefix regex prepended to every failregex; empty string means disabled. */
prefregex: string;
actions: string[];
@@ -76,9 +80,9 @@ export interface JailConfigUpdate {
/** Prefix regex; undefined/null = skip, "" = clear, non-empty = set. */
prefregex?: string | null;
date_pattern?: string | null;
dns_mode?: string | null;
backend?: string | null;
log_encoding?: string | null;
dns_mode?: DNSMode | null;
backend?: BackendType | null;
log_encoding?: LogEncoding | null;
enabled?: boolean | null;
bantime_escalation?: BantimeEscalationUpdate | null;
}
@@ -454,7 +458,7 @@ export interface JailSectionConfig {
findtime: number | null;
bantime: number | null;
action: string[];
backend: string | null;
backend: BackendType | null;
extra: Record<string, string>;
}
@@ -505,13 +509,13 @@ export interface InactiveJail {
/** Failure-counting window in seconds, parsed from findtime. */
find_time_seconds: number;
/** Log encoding, e.g. ``"auto"`` or ``"utf-8"``. */
log_encoding: string;
log_encoding: LogEncoding;
/** Log-monitoring backend. */
backend: string;
backend: BackendType;
/** Date pattern for log parsing, or null for auto-detect. */
date_pattern: string | null;
/** DNS resolution mode. */
use_dns: string;
use_dns: DNSMode;
/** Prefix regex prepended to every failregex. */
prefregex: string;
/** List of failure regex patterns. */

View File

@@ -7,7 +7,7 @@
* - `backend/app/models/geo.py` (GeoDetail / IpLookupResponse)
*/
import type { BantimeEscalation } from "./config";
import type { BantimeEscalation, BackendType, LogEncoding } from "./config";
// ---------------------------------------------------------------------------
// Jail statistics
@@ -48,7 +48,7 @@ export interface JailSummary {
/** Whether the jail is in idle mode (monitoring paused). */
idle: boolean;
/** Backend type used for log access (e.g. `"systemd"`, `"polling"`). */
backend: string;
backend: BackendType;
/** Observation window in seconds before a ban is triggered. */
find_time: number;
/** Duration of a ban in seconds (negative = permanent). */
@@ -88,7 +88,7 @@ export interface Jail {
/** Whether the jail is in idle mode. */
idle: boolean;
/** Backend type (systemd, polling, etc.). */
backend: string;
backend: BackendType;
/** Log file paths monitored by this jail. */
log_paths: string[];
/** Fail-regex patterns used to identify offenders. */
@@ -98,7 +98,7 @@ export interface Jail {
/** Date-pattern used for timestamp parsing, or empty string. */
date_pattern: string;
/** Log file encoding (e.g. `"UTF-8"`). */
log_encoding: string;
log_encoding: LogEncoding;
/** Action names attached to this jail. */
actions: string[];
/** Observation window in seconds. */